checking to see if a textbox control is valid

Posted on 2005-05-17
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
    LVL 1

    Expert Comment

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

    Expert Comment

    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


           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

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

    LVL 23

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now