Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created 2pages login and sign up.. I have used regular expression validator on sign page for first name,middle name and surname..It is giving me error if i enter digits. but when i click on sign up button my record gets inserted even after entering digits. please help
Posted
Updated 16-Jan-14 4:07am
v2
Comments
gettgotcha 16-Jan-14 10:27am    
Can you give the validation condition your using as well as the button click functionality?
Member 10523130 16-Jan-14 10:47am    
yes my validation expression is-
^[a-zA-Z\\s]+$
what is meant by button click functionality? I didn't get it
PaddyM 16-Jan-14 11:01am    
Your expression should not find a match if digits are entered.
Can you post the code for your button click.
Member 10523130 16-Jan-14 11:14am    
I have used asp.net validation control regular expression and i have given above expression. and i have not written any code on button clk for this validation.what shud i do
PaddyM 16-Jan-14 11:29am    
Have you added the ControlToValidate property to your RegularExpressionValidator?

Edit:
You would have added it already because it cannot be left blank, but have you pointed it to the correct control?

Post your code please!

As per your regular expression validation the textbox doesn't accepts digits, if you want to have digits in SurName textbox in the ValidationExpression add 0-9 or \d.

In the code behind on the button click function add a condition
if(Page.IsValid) then only make DB call to insert the text values into database.
 
Share this answer
 
Your code should look like this

SignUp.aspx
XML
<asp:TextBox ID="txtSur" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Invalid Surname" Enabled="True" ControlToValidate="txtSur" ForeColor="Red" ValidationExpression="\b[A-Za-z0-9]+\b" Display="Dynamic" SetFocusOnError="True">
    <asp:Button ID="SignUpButton"
        runat="server" Text="Sign Up" onclick="SignUpButton_Click" />



In SignUp.aspx.cs
C#
protected void SignUpButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //Make a DB call and insert the text values into the DB
            }
        }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900