I have the following input box:
<input id="address1" class="work" />Address1
<input id="address2" class="work" />Address2
<input style="float: right; margin-bottom:20px" type="submit" id="myBtn" value="Submit" class="btn btn-primary" />
I dont want user to type only digits in the input box. I want them to type both digits and alphabets. If the user only type digits then an error is raised when the user clicks on the submit button.
4
Answers
You can use pattern:
Please try this. This only accept alphanumeric characters in the input box
^.*[a-zA-Z].*$
– this pattern seems to work for you:To make some validation before submitting the form when clicking
input[type="submit"]
, you can do this with.click()
and return it withfalse
. This way will block submit event and possibly display any errors if exists. Then, put this regexas validation to get both numbers and alphabets in a string.