checking to see if a textbox control is valid

Posted on 2005-05-17
Medium Priority
Last Modified: 2010-04-07
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


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
Question by:shuittny

Expert Comment

ID: 14018848
use Page.IsValid to know if your page is valid.
LVL 14

Expert Comment

ID: 14018918
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
   'tell user that input was incorrect
End If


Author Comment

ID: 14019492

       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.
LVL 14

Expert Comment

ID: 14019549
Use Validate method of each validator and check their IsValid or Page's IsValid properties

LVL 23

Accepted Solution

b1xml2 earned 300 total points
ID: 14020357
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question