Regular Expression

  • Thread starter Thread starter Jyoti Agarwal
  • Start date Start date
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
 
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
 
Back
Top