Solved

.NET Validation

Posted on 2006-07-03
8
237 Views
Last Modified: 2010-05-18
I havve a form with a Regular Expression Validator.  I am trying to get it to not allow any speical characters only letters and numbers and I also want it to not allow it to start with a number.  What expression would I use and could someone also explain what the expression is doing?
0
Comment
Question by:johnywhite
[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
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17033751
Regular expression:

^[A-Za-z0-9]+$

Starting at the beginning of the string, replicate any number of upper-case letters, lower-case letters and numbers until the end of the string is reached.

Bob
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17033776
Try:

^[A-Za-z]+([A-Za-z]|[0-9])*

The above will match a string that begins with one or more letters, then a sequence of zero or more letters or digits ( | is the alternation symbol)

0
 

Author Comment

by:johnywhite
ID: 17033790
That's what I was looking for thanks.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17033792
Regular Expression to allow alpha a first character and alpha numeric after.

     ^[a-zA-Z][a-zA-Z0-9]*$

Where:
    ^ Marks the begining of the string
    [a-zA-Z] Which only allows one alpha to start the string
    [a-zA-Z0-9] Which only allows one alpha numeric starting at the second character
    * Quantifier Which states allow zero or more of the previous character
    $ Marks the end of the string

Fernando
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17033803
add the $ (end of string) symbol if you dont want leading spaces or spaces within the entire string...

^[A-Za-z]+([A-Za-z]|[0-9])*$

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17033849
Actually the $ lets the regular expression engine know that there should be no more characters. If you do not place it there then you could have invalid characters at the end and as long as the string starts with an alpha followed by 1 or more alpha numeric it will validate.
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17034059
thanks Fernando... I tested it with some leading spaces and mistakenly wrote that... your explanation covers what I was trying to say!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17036940
Good; glad we are on the same track. You have a great day. :=)
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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