validation of input text field in html using javascript

后端 未结 6 1491
鱼传尺愫
鱼传尺愫 2021-02-09 05:22


        
6条回答
  •  甜味超标
    2021-02-09 06:07

    First Name:

    1.word should be atleast 5 letter
    2.No space should be encountered
    3.No numbers and special characters allowed
    4.letters can be repeated upto 3(eg: aa is allowed aaa is not allowed)

    validateForm = function () { return checkName(); } function checkName() { var x = document.myForm; var input = x.name.value; var errMsgHolder = document.getElementById('nameErrMsg'); if (input.length < 5) { errMsgHolder.innerHTML = 'Please enter a name with at least 5 letters'; return false; } else if (!(/^\S{3,}$/.test(input))) { errMsgHolder.innerHTML = 'Name cannot contain whitespace'; return false; }else if(!(/^[a-zA-Z]+$/.test(input))) { errMsgHolder.innerHTML= 'Only alphabets allowed' } else if(!(/^(?:(\w)(?!\1\1))+$/.test(input))) { errMsgHolder.innerHTML= 'per 3 alphabets allowed' } else { errMsgHolder.innerHTML = ''; return undefined; } } .error { color: #E00000; }

提交回复
热议问题