Regular Expression

J

Jyoti Agarwal

Hi All,

I have a textfield which accepts a name. I am validating the text field
using the following statement

Regex.IsMatch(txtFirstName.Text, ("^[a-zA-Z\-\.]"))

The validation requirement is that it should not allow numbers or any
special characters. But the above regular expression still accepts special
characters and numbers.

Can you suggest the correct regular expression?

Thanks in advance

Jyoti
 
F

FUnky

Jyoti Agarwal said:
Hi All,

I have a textfield which accepts a name. I am validating the text field
using the following statement

Regex.IsMatch(txtFirstName.Text, ("^[a-zA-Z\-\.]"))

The validation requirement is that it should not allow numbers or any
special characters. But the above regular expression still accepts special
characters and numbers.

Can you suggest the correct regular expression?

Thanks in advance

Jyoti

I guess u r missing two things - ending the pattern with '$' sign and
specifying the length.
Try using this..
Regex.IsMatch(textBox1.Text, "^[a-zA-Z]{1,}$")

Vivek
 

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

Top