Solved

Help with a regular expression.

Posted on 2009-05-07
4
231 Views
Last Modified: 2012-05-06
I have a regular expression used for input to a textbox control
Hello, I need help understanding a regular expression. (There are two parts to my question.) Here is my regular expression:
ValidationExpression="^[a-zA-Z'.\s]{1,40}$"
I interpret it to ensure the following constraints:
1.) alphanumeric characters only a-z and A-z
2.) Max 1-40 characters
Now what does the ^ character stand for, and the .\s

That is part 1 of my question.

Part 2,
Please modify the regular expression to prevent blank characters. This might be tricky. You see I need to prevent the user from entering nothing into a text box, or just blank spaces.  (Note for various reasons, I am not allowed to use a required field validator control)

0
Comment
Question by:brgdotnet
  • 2
4 Comments
 
LVL 1

Expert Comment

by:seraph_matrix_631
ID: 24331231
ValidationExpression = ereg('[^A-Za-z]'), {1, 40};

$textfield = $_POST['txtTextField'];

if(ValidExpression($name) && (!empy($textfield))
{
  // run the rest of the script
}


Hope this helps
0
 
LVL 1

Accepted Solution

by:
seraph_matrix_631 earned 300 total points
ID: 24331262
also try:

<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtField" ErrorMessage="Letters Only" ValidationExpression="[a-zA-Z]{1,40}">

Change ControlToValidate to whatever field you need validated upon.
Change ErrorMessage to anything you want

and as far as the expression goes change {1, 40}  to the boundary you want to enforce (40 being max), setting it from {1, 40} to {1, +} should allow for unlimited chars if needed.
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 24336522
Hello Seraph. I think there is a big break down in communication here. I wanted to know how to interpret the validation expression I posted. Specifically the characters ^, and  .\s

Part 2 was how to prevent entry of blank characters.

Your reply is confusing. I don't understand what you are telling me?
0
 
LVL 3

Expert Comment

by:channa_m
ID: 24338408
Hello

^ indicates the Beginning of line or string
\s indicates end of line string, space or white space
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question