Solved

Help with a regular expression.

Posted on 2009-05-07
4
237 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
[X]
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
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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