basic .net validation

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hello,

I would like to do several checks on a field "First name".

I would like to check for the following:

No numbers
No spaces
Two characters or more

Anyone know the best way to achieve this?

Regards,

Gary.
 
I assume that you also don't want characters like !"£$%^&*()_-+= and so on??

In which case:

using System.Text.RegularExpressions;

Regex rx = new Regex(@"^[a-zA-Z]{2,}$");

if (rx.IsMatch(txtFirstName.Text))
{
...
}

Off the top of my head, but HTH


Peter
 
Peter said:
Regex rx = new Regex(@"^[a-zA-Z]{2,}$");

Hi,
For the "First name" field validation the expression [A-Z][a-z]+ maybe
will be more suitable.
 
Could be - but it wasn't what the spec said.

:o)


Peter

marss said:
Peter said:
Regex rx = new Regex(@"^[a-zA-Z]{2,}$");

Hi,
For the "First name" field validation the expression [A-Z][a-z]+ maybe
will be more suitable.
 
Whoever saw a logical spec??

Sorry, my cynicism is showing.


Peter
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top