中的电话号码验证

中的电话号码验证

本文介绍了javascript中的电话号码验证码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中的

电话号码验证代码

phone number validation code in javascript

推荐答案

<script type="text/javascript">

function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateUsername(theForm.formtext1);
  reason += validatePassword(theForm.formtext2);
  reason += validateEmail(theForm.formtext5);
  reason += validatePhone(theForm.formtext4);
  reason += validatePasswordMissmatch(theForm.formtext2,theForm.formtext3);
  //reason += validateEmpty(theForm.from);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validatePasswordMissmatch(fld1,fld2)
{
    var error = "";
    if(fld1.value!=fld2.value)
    {
        fld1.style.background = 'Yellow';
        fld2.style.background = 'Yellow';
        error = "Password Missmatch.\n";
    }
    return error;
}


function validateEmpty(fld) {
    var error = "";

    if (fld.value.length == 0) {
        fld.style.background = 'Yellow';
        error = "The required field has not been filled in.\n";
        fld.vlaue="";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores

    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a username.\n";

    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow';
        fld.vlaue="";
        error = "The username is the wrong length.\n";


    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow';
        fld.vlaue="";
        error = "The username contains illegal characters.\n";

    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers

    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 6) || (fld.value.length > 14)) {
        error = "The password is the wrong length. \n";
        fld.vlaue="";
        fld.style.background = 'Yellow';

    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.vlaue="";
        fld.style.background = 'Yellow';

    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.vlaue="";
        fld.style.background = 'Yellow';

    } else {
        fld.style.background = 'White';
    }
   return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+

















<form name="form11" action="Register.jsp" method="get" style="margin:0px" onSubmit="return validateFormOnSubmit(this)">
  <input name="formtext1" type="text" style="position:absolute;width:200px;left:519px;top:299px;z-index:9"  onFocus="showCriteria1()">
  <input name="formtext2" type="password" style="position:absolute;width:200px;left:519px;top:330px;z-index:10" onFocus="showCriteria2()">
  <input name="formtext3" type="password" style="position:absolute;width:200px;left:519px;top:370px;z-index:11" onFocus="showCriteria3()">
  <textarea name="textarea1" style="position:absolute;left:519px;top:403px;width:200px;height:90px;z-index:12" onFocus="showCriteria5()"></textarea>
  <input name="formtext4" type="text" style="position:absolute;width:200px;left:519px;top:511px;z-index:13" onFocus="showCriteria4()">
  <input name="formtext5" type="text" style="position:absolute;width:200px;left:519px;top:556px;z-index:14" onFocus="showCriteria5()">
  <input name="formbutton1" type="submit" style="position:absolute; left:545px; top:605px; z-index:15; width: 100;" value="Register" >
  <input name="formbutton2" type="reset" style="position:absolute; left:417px; top:606px; z-index:16; width: 100;" value="Clear  ">
</form>


这篇关于javascript中的电话号码验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 19:02