Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript表单验证-函数无法执行验证_Javascript_Validation - Fatal编程技术网

javascript表单验证-函数无法执行验证

javascript表单验证-函数无法执行验证,javascript,validation,Javascript,Validation,这是我的表格: 函数formValidator(){ var a=document.getElementById('uname'); var b=document.getElementById('m_photo'); var c=document.getElementById('fname'); var d=document.getElementById('lname'); var e=document.getElementById('p_add'); var f=document.getEl

这是我的表格:

函数formValidator(){
var a=document.getElementById('uname');
var b=document.getElementById('m_photo');
var c=document.getElementById('fname');
var d=document.getElementById('lname');
var e=document.getElementById('p_add');
var f=document.getElementById('c_add');
var g=document.getElementById('b_add');
var h=document.getElementById('country');
var i=document.getElementById('state');
var j=document.getElementById('city');
var k=document.getElementById('pcode');
var l=document.getElementById('id_-proof');
var m=document.getElementById('quali_-proof');
var n=document.getElementById('p_addproof');
var o=document.getElementById('c_addproof');
var p=document.getElementById('resume');
var q=document.getElementById('dob');
var r=document.getElementById('mobile');
var s=document.getElementById('email');
var t=document.getElementById('quali');
var u=document.getElementById('dsgn');
var v=document.getElementById('rep_person');
var w=document.getElementById('join');
var x=document.getElementById('p_hist');
var y=document.getElementById('sh_des');
var z=document.getElementById('app_by');
var A=document.getElementById('accept');
//按表单中显示的顺序检查每个输入!
if(长度限制(a、6、8)){
如果(“==b.值)
{提醒(“请上传会员照片”);
如果(isAlphabet(c,“请只输入名字的字母”)){
如果(isAlphabet(d,“请仅输入姓氏字母”)){
如果(e==null | | e==“”)
{提醒(“请输入您的永久地址”);
如果(f==null | | f==“”)
{提醒(“请输入您当前的地址”);
如果(g==null | | g==“”)
{提醒(“请输入您的分行地址”);
如果(h==null | | h==“”)
{提醒(“请输入国家名称”);
如果(i==null | | i==“”)
{警报(“请输入州名称”);
如果(j==null | | j==“”)
{警报(“请输入城市名称”);
//if(isAlphanumeric(地址,“仅用于地址的数字和字母”)){
如果(是数字(k,“请输入有效的6位Pin码”)){
如果(l==null | | l==“”)
{提醒(“请上传身份证明”);
如果(m==null | | m==“”)
{提醒(“请上传资质证明”);
如果(n==null | | n==“”)
{提醒(“请上传永久地址证明”);
如果(o==null | | o==“”)
{提醒(“请上传当前地址证明”);
如果(p==null | | p==“”)
{提醒(“请上传简历”);
如果(q==null | | q==“”)
{提醒(“请上传D.O.B证明”);
if(长度限制(r,10,10)){
如果(emailValidator,“请输入有效的电子邮件地址”)){
如果(t==null | | t==“”)
{提醒(“请输入资格详细信息”);
如果(进行选择(u,“请选择名称”)){
如果(v==null | | v==“”)
{提醒(“请输入报告人的姓名”);
如果(w==null | | w==“”)
{提醒(“请输入加入日期”);
如果(x==null | | x==“”)
{提醒(“请写一些关于过去历史的东西”);
如果(y==null | | y==“”)
{提醒(“请描述一下该会员”);
如果(z==null | | z==“”)
{警报(“空字段:指定人”);
如果(做出选择(A,“请接受条款和条件”)){
返回true;
}}
}}
}}
}}
function formValidator(){
var a = document.getElementById('uname');
var b = document.getElementById('m_photo');
var c= document.getElementById('fname');
var d= document.getElementById('lname');
var e= document.getElementById('p_add');
var f= document.getElementById('c_add');
var g= document.getElementById('b_add');
var h= document.getElementById('country');
var i= document.getElementById('state');
var j= document.getElementById('city');
var k= document.getElementById('pcode');
var l= document.getElementById('id_proof');
var m= document.getElementById('quali_proof');
var n= document.getElementById('p_addproof');
var o= document.getElementById('c_addproof');
var p= document.getElementById('resume');
var q= document.getElementById('dob');
var r= document.getElementById('mobile');
var s= document.getElementById('email');
var t= document.getElementById('quali');
var u= document.getElementById('dsgn');
var v= document.getElementById('rep_person');
var w= document.getElementById('join');
var x= document.getElementById('p_hist');
var y= document.getElementById('sh_des');
var z= document.getElementById('app_by');
var A= document.getElementById('accept');

// Check each input in the order that it appears in the form!
if(lengthRestriction(a, 6, 8)){
    if(""==b.value)
        {alert("Please Upload the Member Photo");
            if(isAlphabet(c, "Please enter only Alphabets for First Name")){
                if(isAlphabet(d, "Please enter only Alphabets for Last Name")){
                    if(e==null || e=="")
                        {alert("Please Enter your Permanent Address");
                            if(f==null || f=="")
                                {alert("Please Enter your Current Address");
                                    if(g==null || g=="")
                                        {alert("Please Enter your Branch Address");
                                            if(h==null || h=="")
                                                {alert("Please Enter the Country Name");
                                                    if(i==null || i=="")
                                                        {alert("Please Enter the State Name");
                                                            if(j==null || j=="")
                                                                {alert("Please Enter the City Name");

    //if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
            if(isNumeric(k, "Please enter a valid 6 digit Pin Code")){
                if(l==null || l=="")
                    {alert("Please Upload the Id-Proof");
                        if(m==null || m=="")
                            {alert("Please Upload the Qualification Proof");
                                if(n==null || n=="")
                                    {alert("Please Upload the Permanent Address Proof");
                                        if(o==null || o=="")
                                            {alert("Please Upload the Current Address Proof");
                                                if(p==null || p=="")
                                                    {alert("Please Upload the Resume");
                                                        if(q==null || q=="")
                                                            {alert("Please Upload the D.O.B Proof");
                                                                if(lengthRestriction(r,10,10)){
                                                                    if(emailValidator(s, "Please enter a valid email address")){
                                                                        if(t==null || t=="")
                                                                            {alert("Please Enter the Qualification Details");
                                                                                if(madeSelection(u, "Please Choose a Designation")){
                                                                                    if(v==null || v=="")
                                                                                        {alert("Please Enter the name of the Reporting Person");
                                                                                            if(w==null || w=="")
                                                                                                {alert("Please Enter the Joining Date");
                                                                                                    if(x==null || x=="")
                                                                                                        {alert("Please Write Something about Past History");
                                                                                                            if(y==null || y=="")
                                                                                                                {alert("Please give some Description about the Member");
                                                                                                                    if(z==null || z=="")
                                                                                                                        {alert("Empty Field: APPOINTED BY");
                                                                                                                            if(madeSelection(A, "Please Accept the terms and conditions")){
                                                                                            return true;
                                                                    }}
                                                                }}
                                                            }}
                                                        }}
                                                    }}
                                                }}
                                            }}
                                        }}
                                    }}
                                }}
                            }}
                        }}
                    }}
                }

return false;


}
 function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
    alert(helperMsg);
    elem.focus(); // set the focus to this input
    return false;
}
return true;
}

function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
    return true;
}else{
    alert(helperMsg);
    elem.focus();
    return false;
}
}

function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
    return true;
}else{
    alert(helperMsg);
    elem.focus();
    return false;
}
}

function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
    return true;
}else{
    alert(helperMsg);
    elem.focus();
    return false;
}
}

function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
    return true;
}else{
    alert("Please enter between " +min+ " and " +max+ " characters");
    elem.focus();
    return false;
}
}

function madeSelection(elem, helperMsg){
if(elem.value == "Select Designation"){
    alert(helperMsg);
    elem.focus();
    return false;
}else
    {
    return true;
}
}

function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
    return true;
}else{
    alert(helperMsg);
    elem.focus();
    return false;
}
}
if(lengthRestriction(a, 6, 8)){
    if(""==b.value)
        {alert("Please Upload the Member Photo");
            if(isAlphabet(c, "Please enter only Alphabets for First Name")){
<input id="fname" type="text" class="required" data-validation="alphanumeric"
        data-error="Please enter your first name." />

<input id="age" type="text" class="required" data-validation="numeric"
    data-error="Please enter your age." />

<input id="accept" type="checkbox" class="required" data-validation="check" 
    data-error="Please accept the terms of agreement." />
function validateForm() {
    // get the .required fields as NodeList
    var requiredElems = document.getElementsByClassName('required') || 
                            document.querySelectorAll('.required');
    // validate fields one-by-one
    for (var i = 0; i < requiredElems.length; i++) {
        var elem = requiredElems[i];
        if (validateField(elem) === false) {
            alert(elem.getAttribute('data-error')); //get the error message from the custom data attribute and alert.
            elem.focus();
            return false; //break;
        }
    }
    return true;
}

function validateField(elem) {
    var rxp, valid = true,
        // get the validation type from the custom data attribute.
        validationType = elem.getAttribute('data-validation');
    // all validation logic in one place
    switch (validationType) {
        case 'alphanumeric':
            rxp = /^[0-9a-zA-Z]+$/;
            valid = rxp.test(elem.value);
            break;
        case 'numeric':
            rxp = /^[0-9]+$/;
            valid = rxp.test(elem.value);
            break;
        case 'email':
            rxp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
            valid = rxp.test(elem.value);
            break;
        case 'check':
            valid = elem.type == 'checkbox' ? elem.checked : true;
            break;
    }
    
    return valid;
}