开发者

Javascript Form Validation 4 Number Option

开发者 https://www.devze.com 2023-02-25 00:56 出处:网络
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 numb

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");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号