?
Solved

.NET Validation

Posted on 2006-07-03
8
Medium Priority
?
239 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 2000 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
Technology Partners: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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