Solved

Help with a regular expression.

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now