Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help with a regular expression.

Posted on 2009-05-07
4
232 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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