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

Re: Regular Expression by FUnky

FUnky
Mon Mar 13 03:58:29 CST 2006


"Jyoti Agarwal" <jagarwal@annetsite.com> wrote in message
news:e07B58nRGHA.4956@TK2MSFTNGP09.phx.gbl...
> 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