Page.Invalid

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

Hello,

I know this issue has been raised many times in the past, but I couldn't
find a solution from reading many posts from a google search, so I am
posting it again.

I placed a RegularExpressionvalidator on a webform to test a textbox for a
proper email format. I am trying to test for a failure but can't seem to
get a value. Here is what I tried:

EmailValidator.Validate()
If Not Page.IsValid Then
Beep()
txtEmail.Focus()
End If

ALSO

EmailValidator.Validate()
If Page.IsValid = False Then
Beep()
txtEmail.Focus()
End If

THEN

EmailValidator.Validate()
If Page.IsValid Then
'nothing
Else
Beep()
txtEmail.Focus()
End If

None of these three methods works, but

"If Page.IsValid Then..." form

Is recognized.



Thanks for any help

God Bless,
 
Some more information is required. What is in the textbox and what is
the regex you are using?

Are you saying that the page is always valid?

Regards
Ray
 
Hello Ray,

The textbox is a texbox control on a webform, called txtEmail. An email
address is what I am testing.

I don't know what you mean by "regex". It seems like the page is always
valid. I don't know. I don't know how to test it. All I seem to get is a
True result though.

All I am looking to do it to validate data before the button procedure runs,
putting the focus back to the offending textox.


Mark
 
Ray Booysen said:
Some more information is required. What is in the textbox and what is the
regex you are using?

Are you saying that the page is always valid?

No. I tested the value:

EmailValidator.Validate()
MsgBox(Page.IsValid, MsgBoxStyle.Information, "Page.Invalid")

When a correct email address is entered, the msgbox returns, "True"
otherwise it doesn't come up.

The Validation control responds with a message in either case, but I need to
trap the result.
 
The regular expression validator compares the contents of your textbox
against a regular expression (regex) If you haven't typed in the regular
expression the validator is always going to return true. You need to
get a regex for an email address like this one:
^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$
 
For anyone whop runs into this same issue. The procedure is being run from
a button, which has a default value of True for the CausesValidation
property. Setting the property to False resolved it.
 
Back
Top