C# .NET - Regular expression for validating fields

Asked By Chester Thomas on 28-Aug-09 09:04 AM

I have 2 fields that I want validated that either of them should contain a contact number.

asp:TextBox ID="CellTextBox" runat="server" 

asp:TextBox ID="MobileTextBox" runat="server" 


Regular expression for validating fields - Chester Thomas replied to Chester Thomas on 28-Aug-09 09:06 AM

So for instance if either one of them has a value then all should be ok but if they are both blank then a notification should be displayed

chek it - balaram krishna replied to Chester Thomas on 28-Aug-09 09:57 AM

Just on the two text boxes take two regular expression validator control. According to ur Requirement mention the expression with in the properties of the validation controls.U can also place the Requried Field validator control.For Ur Requrement check the following Expressions....:

\d{10}----->10 digit number
\d{1,4}----->1 to 4 digits.
\D{4}------->4 char string
[A-Z]{5}----->5 char string with Upper case letters.
Chester Thomas replied to balaram krishna on 28-Aug-09 10:02 AM

Thanks it helped me also with another problem I am having.

What I need though is to check both fields and make sure that at least one of them is filled.

Call this Javascript function. - [)ia6l0 iii replied to Chester Thomas on 28-Aug-09 01:44 PM
<script type ="text/javascript" >
    function MobileNumberValidate()
        var cellValue   = document.getElementById("CellTextBox").value;
   var mobValue = document.getElementById("MobileTextBox").value;
         if ((cellValue = ="") && (mobValue = = "" ) )
     alert("Please enter alteast one number.");
TextBox Validation - Kirtan Patel replied to [)ia6l0 iii on 30-Aug-09 07:39 AM

Hi You can Do it With Following Code :)

protected void Button1_Click(object sender, EventArgs e)


        if (TextBox1.Text.Trim() != "" || TextBox2.Text.Trim() != "")


            // do whatever you want to do





            Page.RegisterClientScriptBlock("","<script>alert('Any One number is Needed!!')</script>");