Javascript Form Validation 4 Number Option
I've been searching this website for a tutorial on how to write a s开发者_开发问答cript that validates a form for four specific numbers. If the data is entered and does not match any of the four numbers, it should alert a 'Not Valid' message.
var input = document.getElementById("myInput");
var validNumbers = /^(123|777|989|111)$/;
var isFormValid = validNumbers.test(input.value);
if (!isFormValid)
{
alert("Not Valid");
}
精彩评论