Hi i am using following code for phone number validations, after 10 digits it will display error message "Please enter only 10 digits" but after 10 digits if we enter number means it will add number so please help me this textbox must not add number after 10 digits.
private void txtcontactno_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtcontactno.Text,@"^([0-9]{1,10})$"))
{
//MessageBox.Show("match pattern");
// Do something here
}
else
{
MessageBox.Show("Please enter only 10 digits");
txtcontactno.Focus();
}
}
Vipul MalhotraRank #276 · 9.1K reputationPosted Aug 10, 2015, 4:29 AM EDT
Amitesh VermaRank #2,535 · 552 reputationPosted Aug 10, 2015, 3:00 AM EDT
- function phonenumber(inputtxt)
- {
- var phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
- if((inputtxt.value.match(phoneno))
- {
- return true;
- }
- else
- {
- alert("message");
- return false;
- }
http://www.w3resource.com/javascript/form/phone-no-validation.phpIndra Kumar S25 reputationPosted Aug 10, 2015, 3:10 AM EDT
Amitesh VermaRank #2,535 · 552 reputationPosted Aug 10, 2015, 3:16 AM EDT
Raja TRank #685 · 3.5K reputationPosted Aug 10, 2015, 3:19 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts