Input field to only accept a specific number
I have created a form and now I want to add an input field inside it which
would only accept a specific number i.e. the digit '4'. This is more like
a spam check where the user is asked that 'What is the answer of 1+3?' and
then he/she would've to enter the digit '4', in the input field, in order
for the form to get processed. This could also work in a manner that if
any other number is entered inside the input field and the form is
submitted, a pop up window is fired explaining the error.
I have created a jsfiddle which only accepts the digit 4 but sadly it is
allow accepting 'full stops'.
HTML:
<input id="humancheck" type="text" maxlength="1" name="humancheck"
required />
Javascript:
jQuery('#humancheck').keyup(function () {
this.value = this.value.replace(/[^4-4\.]/g,'');
});
No comments:
Post a Comment