B
Bibe
I've been trying to get this going for awhile now, and need help. I've
done a regex object, and when I use IsMatch, it's behavior is quite weird.
I am trying to use Regex to make sure that a variable is only
alphanumeric (no strange characters).
Here's the code:
Regex regExp = new Regex("[a–zA–Z0–9_]*");
// note: _username is a HtmlInputText
if ( !(regExp.IsMatch(_username.Value)) )
{
//should only go in here if _username contains non-alphanumeric
characters
}
Even if I put strange characters, such as []%^$#!@#, it never goes in
that if block. I've tried getting rid of the ! such as
if (regExp.IsMatch(_username.Value)) { //code }
and it always goes in this if block no matter what I input, wether it
contains only alphanumeric or non-alphanumeric.
Any ideas?
done a regex object, and when I use IsMatch, it's behavior is quite weird.
I am trying to use Regex to make sure that a variable is only
alphanumeric (no strange characters).
Here's the code:
Regex regExp = new Regex("[a–zA–Z0–9_]*");
// note: _username is a HtmlInputText
if ( !(regExp.IsMatch(_username.Value)) )
{
//should only go in here if _username contains non-alphanumeric
characters
}
Even if I put strange characters, such as []%^$#!@#, it never goes in
that if block. I've tried getting rid of the ! such as
if (regExp.IsMatch(_username.Value)) { //code }
and it always goes in this if block no matter what I input, wether it
contains only alphanumeric or non-alphanumeric.
Any ideas?