Solved

.NET Validation

Posted on 2006-07-03
8
238 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
Industry Leaders: 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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