checking to see if a textbox control is valid

Does anyone know how to check if a textbox value passes a regular validation value.  I can do it easily from the grid approach but not via actual code

ex.

sub customFunc(......)
      Dim regExpVal as RegularExpressionValidator

      regExpVal.ControlToValidate = txtBox1.text
      regExpVal.ValidationExpression = (d{2})
     
 
    ' if textbox1.text not(regExpVal.ValidationExpression) then ........I'm not sure if this is valid or would work if it is valid
         response.write("this field isn't a valid field")
     end if
end sub
shuittnyAsked:
Who is Participating?
 
b1xml2Connect With a Mentor Commented:
if the CustomValidators are all hooked up at Page_Init or Page_Load then all you have to do is:
Page.Validate() 'calling the page validate method causes all validators to be validate
If Page.IsValid Then

End If
0
 
JayWhiteCommented:
use Page.IsValid to know if your page is valid.
0
 
RamuncikasCommented:
Wouldn't it be more simple way to set RegularExpressionValidator control on a page and set it's ControlToValidate, ValidationExpression, Display, ErrorMessage, EnableClientScript properties to desired values. Then all you have to do is

If Page.IsValid Then
   'do your desired processing
Else
   'tell user that input was incorrect
End If


Ramuncikas
0
 
shuittnyAuthor Commented:
True,

       I'm embedding the regularexpressionvalidation within a custom validation script that I wrote.  I origninally have a reg.exp.val for all of my textboxes along with a custom val for those same textboxes.  I just wanted to see if I could combine everything into one call.
0
 
RamuncikasCommented:
Use Validate method of each validator and check their IsValid or Page's IsValid properties

Ramuncikas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.