JS一览


function foo(){
    var aInput = document.getElementsByTagName("input");
    for (var i = 0 ; i < aInput.length ; i++ ){
        if(aInput[i].name == 'isPlusAndOnlineAccount' && aInput[i].checked == true){
            //alert(aInput[i].value);
            return true;
        }
    }
    return false;
}



function checkBlank(field,id,msg)
{
    var formName = document.forms['/ICARD/icardApplicationNewContext'];
    if(document.getElementById(field) != null)
    {
        if(document.getElementById(field).value =='')
        {
            if(document.getElementById(id.toString()) != null)
            {
                document.getElementById(id.toString()).innerHTML=msg;
            }
        }
        else
        {
            if(document.getElementById(id.toString()) != null)
            {
                document.getElementById(id.toString()).innerHTML="";
            }
        }
    }
}





function checkAlphaWithSpecialCharacters(field,id,msg)
{
    var flag="0";
    var valid=" '-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var fvalue =document.getElementById(field).value;
    for (var i=0; i<fvalue.length; i++)
    {
        temp = "" + fvalue.substring(i,i+1);
        if (valid.indexOf(temp) < 0)
        {
            flag="1";
            break;
        }
    }
    if(flag!="0")
    {
        document.getElementById(id).innerHTML=msg;
    }
    else
    {
        document.getElementById(id).innerHTML="";
    }
}


function checkEmail2(obj) {
    var emailStr=document.getElementById(obj).value;
    var valid = true;
    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var quotedUser="(\"[^\"]*\")"
    var atom=validChars + '+'
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
    var atIndex = emailStr.lastIndexOf('\@');
    var dotIndex = emailStr.lastIndexOf('.');
    
    if(atIndex == -1 || dotIndex == -1|| (atIndex > dotIndex) ){
        valid = false;
    }

    var matchArray=emailStr.match(emailPat)
    if (matchArray==null)
    {
        valid = false;
    } else
    {

        var user=matchArray[1]
        var domain=matchArray[2]

        // See if "user" is valid
        if (user.match(userPat)==null)
        {
            valid = false;
        }

        // Domain is symbolic name
        var domainArray=domain.match(domainPat)
        if (domainArray==null)
        {
            valid = false
        }
    }

    if (!valid)
    {
          
        //obj.focus();
        return false;
    }
    return true;
}

function validateEmail(field,id,msg){
    var flag="0";

    if((document.getElementById("emailAddress")!=null && document.getElementById("emailAddress").value!='') ) {
        if (document.getElementById(field).value!= ""){
            if (!checkEmail2(field)){
               
                flag="1";
              }
        }
    }
    if(flag=="1"){
        document.getElementById(id.toString()).innerHTML=msg;
    }
    else{
        document.getElementById(id).innerHTML="";
    }
}


function handleMotherMaidenName()
{
    checkBlank('motherMaidenName','err_msg_mot_maid_blank',"Please enter your mother\'s maiden name");
    checkAlphaWithSpecialCharacters('motherMaidenName','err_msg_mot_maid_alpha','Please check your mother\'s name entered. Please enter only alphabetic characters in this field.');
}

function handleNationality()
{
    checkBlank('nationality','nationality_blank',"Please enter your nationality");
    checkAlphaWithSpecialCharacters('nationality','nationality_alpha',"Please check your nationality entered. Please enter only alphabetic characters in this field.");
}

function handleTFN1()
{
    checkBlank('TFN1','TFN1_blank',"Please enter your TFN1");
    checkAlphaWithSpecialCharacters('TFN1','TFN1_alpha','Please check your TFN1 entered. Please enter only alphabetic characters in this field.');
}

function handleTFN2()
{
    checkBlank('TFN2','TFN2_blank',"Please enter your TFN2");
    checkAlphaWithSpecialCharacters('TFN2','TFN2_alpha','Please check your TFN2 entered. Please enter only alphabetic characters in this field.');
}

function handleTFN3()
{
    checkBlank('TFN3','TFN3_blank',"Please enter your TFN3");
    checkAlphaWithSpecialCharacters('TFN3','TFN3_alpha','Please check your TFN3 entered. Please enter only alphabetic characters in this field.');
}


function handleEMAIL()
{
    checkBlank('emailAddress','emailAddress_blank',"Please enter your Email");
    validateEmail('emailAddress',"emailAddress_alpha","Please enter your email address in the following format: user@domain.com");
}

function handleException()
{
    checkBlank('exception','exception_blank',"Please select the exception");
    checkAlphaWithSpecialCharacters('exception','exception_alpha','Please select the exception. Please enter only alphabetic characters in this field.');
}


<!--validation for isNonResORClaimExcORNoQuoteExc -->


function handleisNonResORClaimExcORNoQuoteExc()
{
    checkBlank('isNonResORClaimExcORNoQuoteExc','isNonResORClaimExcORNoQuoteExc_blank',"Please select the isNonResORClaimExcORNoQuoteExc");
    //checkAlphaWithSpecialCharacters('isNonResORClaimExcORNoQuoteExc','isNonResORClaimExcORNoQuoteExc_alpha','Please select the isNonResORClaimExcORNoQuoteExc. Please enter only alphabetic characters in this field.');
}




//validate the Form

function validateField(field){
//alert("4");
    if(field!=null){
    //alert("5");
        if(field.name == "nationality"){
        //alert("6");
                if(field.value ==''){
                    checkBlank('nationality','nationality_blank',"Please enter your nationality");
                    //alert("7");
                    return 1;
                }else{
                    checkAlphaWithSpecialCharacters('nationality','nationality_alpha',"Please check your nationality entered. Please enter only alphabetic characters in this field.");
                    return 2;
                }
        }
        
        if(field.name == "TFN1"){
                if(field.value == ''){
                checkBlank('TFN1','TFN1_blank',"Please enter your TFN1");
                return 1;
                }else{
                checkAlphaWithSpecialCharacters('TFN1','TFN1_alpha','Please check your TFN1 entered. Please enter only alphabetic characters in this field.');
                return 2;
                }
        }
        
        if(field.name == "TFN2"){
                if(field.value == ''){
                checkBlank('TFN2','TFN2_blank',"Please enter your TFN2");
                return 1;
                }
                else{
                checkAlphaWithSpecialCharacters('TFN2','TFN2_alpha','Please check your TFN2 entered. Please enter only alphabetic characters in this field.');
                return 2;
                }
        }
        
        if(field.name == "TFN3"){
                if(field.value == ''){
                checkBlank('TFN3','TFN3_blank',"Please enter your TFN3");
                return 1;
                }
                else{
                checkAlphaWithSpecialCharacters('TFN3','TFN3_alpha','Please check your TFN3 entered. Please enter only alphabetic characters in this field.');
                return 2;
                }
        }
        
        if(field.name == "emailAddress"){
                if(field.value == ''){
                checkBlank('emailAddress','emailAddress_blank',"Please enter your Email");
                return 1;
                }
                else{
                validateEmail('emailAddress',"emailAddress_alpha","Please enter your email address in the following format: user@domain.com");
                return 2;
                }
        }
        /*
        if(field.name == "exception"){
                if(field.value == ''){
                checkBlank('exception','exception_blank',"Please select the exception");
                return 1;
                }
                else{
                checkAlphaWithSpecialCharacters('exception','exception_alpha','Please select the exception. Please enter only alphabetic characters in this field.');
                return 2;
                }
        }
        */
        if(field.name == "isNonResORClaimExcORNoQuoteExc"){
                if(!(document.getElementById('isNonResORClaimExcORNoQuoteExc').checked)){
                
            checkAlphaWithSpecialCharacters('isNonResORClaimExcORNoQuoteExc','isNonResORClaimExcORNoQuoteExc_alpha','Please select the isNonResORClaimExcORNoQuoteExc.');
                return 1;
                }
                else{
    
                checkAlphaWithSpecialCharacters('isNonResORClaimExcORNoQuoteExc','isNonResORClaimExcORNoQuoteExc_alpha','Please select the isNonResORClaimExcORNoQuoteExc. Please enter only alphabetic characters in this field.');
                return 2;
                }
        }
        
        if(field.name == 'isPlusAndOnlineAccount'){
                //alert("kaishixuanle");
                if(foo()){
                //alert("choose one ");
                return 1;
                }
                else{
                //alert("choose nothing!");
                checkAlphaWithSpecialCharacters('isPlusAndOnlineAccount','isPlusAndOnlineAccount_alpha','Please select the account type.');
                return 2;
                }
        }
        
        
        
    }
    
}


function validateForm(){
//alert("2");
    var errorCounter = 0;
    //alert("3");
    switch(validateField(document.getElementById('nationality'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    //alert("3");
    switch(validateField(document.getElementById('TFN1'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    //alert("4");
    switch(validateField(document.getElementById('TFN2'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    switch(validateField(document.getElementById('TFN3'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    switch(validateField(document.getElementById('emailAddress'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    switch(validateField(document.getElementById('exception'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    switch(validateField(document.getElementById('isNonResORClaimExcORNoQuoteExc'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    switch(validateField(document.getElementById('isPlusAndOnlineAccount'))){
        case 0:break;
        case 1:errorCounter = errorCounter + 1;break;
        case 2:errorCounter = errorCounter + 1;break;
    }
    //alert(errorCounter);
    if(errorCounter == 0){
        return true;
    }else{
        return false;
    }
}










function submitEntry()
{
//alert("1");
if(document.getElementById('acceptTerms')!=null){
    if(!(document.getElementById("acceptTerms").checked))
    alert("Please indicate you agree with the Terms and Conditions!");
}

if(document.getElementById('agreeEStatement')!=null){
    if(!(document.getElementById("agreeEStatement").checked))
    alert("Please indicate you agree with the Terms and Conditions!");
}

validateForm();

}  

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值