Solved

Help with a regular expression.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hovering effect 9 47
Achieve json result 2 65
Host asp.net pages 5 25
Javascript alert is skipped before a Response.Redirect is executed in vb.net asp.net 9 26
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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

19 Experts available now in Live!

Get 1:1 Help Now