Solved

.NET Validation

Posted on 2006-07-03
8
233 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
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
 
LVL 62

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
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.

 
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 62

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 62

Expert Comment

by:Fernando Soto
ID: 17036940
Good; glad we are on the same track. You have a great day. :=)
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
String manipulation 15 64
Round up to 100% in .NET 10 79
Access properties in nested observable collections 8 23
how to read json value 2 27
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

937 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

10 Experts available now in Live!

Get 1:1 Help Now