一个涵盖很多常用验证的js文件check.js--Majoy7给的
check.js
- var is_rep = true;
- function urlgoto(inputurl) {
- alert(inputurl);
- var form1 = document.getElementById("form1");
- form1.action = inputurl;
- form1.submit();
- }
- function intCheck(input, len) {
- var intv = input.value.replace(/(^/s*)|(/s*$)/g, "");
- if (intv !== "") {
- if (!/^/d*$/.test(intv)) {
- alert("/u5fc5/u987b/u8f93/u5165/u6570/u5b57/uff01");
- errorValueDeal(input);
- return (false);
- }
- lenCheck(input, len);
- }
- }
- function positiveNumCheck(input, len) {
- var intv = input.value.replace(/(^/s*)|(/s*$)/g, "");
- if (intv !== "") {
- if (!/^/d*$/.test(intv) || intv < 1) {
- alert("/u8f93/u5165/u7684/u503c/u5fc5/u987b/u4e3a/u5927/u4e8e0/u7684/u6b63/u6574/u6570/uff01");
- errorValueDeal(input);
- return (false);
- }
- var povalue = 1;
- for (var i = 0; i < len; i++) {
- povalue = povalue * 10;
- }
- var length = length_all(intv);
- if (length > len) {
- alert("/u8f93/u5165/u7684/u503c/u8fc7/u5927/uff0c/u5fc5/u987b/u4e3a1-" + (povalue - 1) + "/u7684/u6b63/u6574/u6570/uff01");
- errorValueDeal(input);
- return (false);
- }
- }
- }
- function checkcapital(input, len) {
- str = input.value.replace(/(^/s*)|(/s*$)/g, "");
- if (str !== "") {
- if (!/^/d+/./d{1,2}$/.test(str) && !/^/d+$/.test(str)) {
- alert("/u5fc5/u987b/u8f93/u5165/u6570/u5b57,/u5982/uff1a12.0/u621612/uff01");
- errorValueDeal(input);
- return (false);
- }
- if (str.length > len) {
- alert("/u8f93/u5165/u7684/u5b57/u7b26/u8fc7/u5927/uff01");
- errorValueDeal(input);
- return (false);
- }
- return (true);
- }
- }
- //get the length
- function length_all(str) {
- var len;
- var i;
- len = 0;
- for (i = 0; i < str.length; i++) {
- if (str.charCodeAt(i) > 255) {
- len += 2;
- } else {
- len++;
- }
- }
- return len;
- }
- function lenCheck(inp, len) {
- var str = inp.value.replace(/(^/s*)|(/s*$)/g, "");
- if (str !== "") {
- var length = length_all(str);
- if (length > len) {
- alert("/u5b57/u7b26/u957f/u5ea6/u8fc7/u5927/uff0c/u4e0d/u80fd/u8d85/u8fc7" + len + "/u4f4d/uff01");
- errorValueDeal(inp);
- return (false);
- }
- return (true);
- }
- }
- function charCheck(inp, len) {
- var ch = inp.value.replace(/(^/s*)|(/s*$)/g, "");
- if (ch !== "") {
- if (!/^[a-zA-Z/d]*$/.test(ch) && ch != "") {
- alert("/u53ea/u80fd/u8f93/u5165/u5b57/u6bcd/u548c/u6570/u5b57!/u5982/uff1aabc123");
- (inp);
- return (false);
- }
- lenCheck(inp, len);
- }
- }
- function isDate(obj) {
- var bDate;
- var day = obj.value.replace(/(^/s*)|(/s*$)/g, "");
- if (day == null || day == "") {
- return false;
- }
- bDate = /^((((1[6-9]|[2-9]/d)/d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]/d|3[01]))|(((1[6-9]|[2-9]/d)/d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]/d|30))|(((1[6-9]|[2-9]/d)/d{2})-0?2-(0?[1-9]|1/d|2[0-8]))|(((1[6-9]|[2-9]/d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/.test(day);
- if (!bDate && day != "") {
- alert("/u65e5/u671f/u683c/u5f0f/u4e0d/u6b63/u786e!/u5982/uff1a2008-01-01");
- try {
- obj.focus();
- }
- catch (e) {
- }
- return true;
- }
- return false;
- }
- function isPhoneNumber(obj) {
- var phoneNum;
- var mphoneNum;
- mphoneNum = /^((/(/d{3}/))|(/d{3}/-))?13/d{9}$/.test(obj.value.replace(/(^/s*)|(/s*$)/g, ""));
- phoneNum = /^((/(/d{3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}$/.test(obj.value.replace(/(^/s*)|(/s*$)/g, ""));
- if (!phoneNum && !mphoneNum && obj.value != "") {
- alert("/u7535/u8bdd/u53f7/u7801/u683c/u5f0f/u9519/u8bef/uff01/u5982/uff1a0731-1234567 13412345678");
- try {
- obj.focus();
- }
- catch (e) {
- }
- return true;
- }
- return false;
- }
- function isEmail(obj) {
- var bMail;
- bMail = /^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/.test(obj.value);
- if (!bMail && obj.value != "") {
- alert("/u90ae/u7bb1/u683c/u5f0f/u9519/u8bef/uff01/u5982/uff1a12@12.com");
- try {
- obj.focus();
- }
- catch (e) {
- }
- return true;
- }
- lenCheck(obj, "50");
- return false;
- }
- function isIP(obj) {
- var bIP;
- bIP = /^(/d+)/.(/d+)/.(/d+)/.(/d+)$/.test(obj.value);
- if (bIP) {
- bIP = (RegExp.$1 <= 255) && (RegExp.$2 <= 255) && (RegExp.$3 <= 255) && (RegExp.$4 <= 255);
- }
- if (!bIP && obj.value != "") {
- alert("IP/u683c/u5f0f/u9519/u8bef/uff01");
- try {
- obj.focus();
- }
- catch (e) {
- }
- return true;
- }
- return false;
- }
- function errorValueDeal(input) {
- input.focus();
- input.select();
- }
- function is_repeat(url, name, ord, id) {
- url += "&name=";
- url += name.value;
- url += "&ord=";
- url += ord.value;
- if (id != null) {
- url += "&id=";
- url += id.value;
- }
- var myAjax = new Ajax.Request(url, {method:"POST", asynchronous:false, onSuccess:function (transport) {
- var ret = transport.responseText;
- if (ret == "1") {
- alert("/u8be5/u540d/u79f0/u5df2/u7ecf/u5b58/u5728/uff0c/u8bf7/u91cd/u65b0/u8f93/u5165/uff01");
- name.focus();
- name.select();
- is_rep = false;
- } else {
- if (ret == "2") {
- alert("/u663e/u793a/u4f4d/u7f6e/u91cd/u590d/uff0c/u8bf7/u91cd/u65b0/u8f93/u5165/uff01");
- ord.focus();
- ord.select();
- is_rep = false;
- } else {
- is_rep = true;
- }
- }
- }});
- return is_rep;
- }
- function is_org_repeat(url, name, id) {
- url += "&name=";
- url += name.value;
- if (id != null) {
- url += "&id=";
- url += id.value;
- }
- var my_Ajax = new Ajax.Request(url, {method:"POST", asynchronous:false, onSuccess:function (transport) {
- var rep = transport.responseText;
- if (rep == "1") {
- alert("/u8be5/u540d/u79f0/u5df2/u7ecf/u5b58/u5728/uff0c/u8bf7/u91cd/u65b0/u8f93/u5165/uff01");
- name.focus();
- name.select();
- is_rep = false;
- } else {
- is_rep = true;
- }
- }});
- return is_rep;
- }
- function is_model_repeat(url, name) {
- url += "&name=";
- url += name.value;
- var my_Ajax = new Ajax.Request(url, {method:"POST", asynchronous:false, onSuccess:function (transport) {
- var rep = transport.responseText;
- if (rep == "1") {
- alert("/u6a21/u677f/u540d/u79f0/u5df2/u7ecf/u5b58/u5728/uff0c/u8bf7/u91cd/u65b0/u8f93/u5165/uff01");
- name.focus();
- is_rep = false;
- } else {
- is_rep = true;
- }
- }});
- return is_rep;
- }