Autor: Editor of the Prodigal Son
From:http://bbs.51js.com/thread-68161-1-1.html
Form Validation Class
function Validatorclass ()
{
var IsError = false;
Check the name, you can only enter Chinese, letters, numbers, underscores
This. Chkname = function (obj,msg)
{
if (IsError) return;
if (Obj.value.Trim (). length<2| | (/[^u4e00-u9fa5w]/.test (Obj.value.Trim ())) Errorhandle (OBJ,MSG);
}
Check email address
This. Chkemail = function (obj,msg)
{
if (IsError) return;
if (!/^w+@w+.: com|cn|org|net|cc|tv|info|com.cn|net.cn|org.cn|gov.cn) $/i.test (Obj.value.Trim ()) Errorhandle ( OBJ,MSG);
}
Check the name, can only be Chinese, and can not be empty
This. Chkplace = function (obj,msg)
{
if (IsError) return;
if (Obj.value.Trim (). length<1| | (/[^u4e00-u9fa5]/.test (Obj.value.Trim ())) Errorhandle (OBJ,MSG);
}
Check Detailed Address
This. chkaddress = function (obj,msg)
{
if (IsError) return;
if (Obj.value.Trim (). length<2) Errorhandle (obj,msg);
}
Check message encoding
This. Chkpostnumber = function (obj,msg)
{
if (IsError) return;
if (!) ( /^d{6}$/.test (Obj.value.Trim ())) Errorhandle (obj,msg);
}
Check your phone number.
This. Chkmobile = function (obj,msg)
{
if (IsError) return;
if (!) ( /^ (?: 13d|159)-?d{5} (D{3}|*{3}) $/.test (Obj.value.Trim ())) Errorhandle (obj,msg);
}
Check the fixed phone number
This. Chkphone = function (obj,msg)
{
if (IsError) return;
if (!) ( (/^d{3,4}-?d{4,5} (D{3}|*{3}) $/.test (Obj.value.Trim ()))) Errorhandle (OBJ,MSG);
}
Submitting Form Events
This. Submit = function (form,msg)
{
if (IsError) return;
if (msg) alert (msg);
Form.submit ();
}
Error handling
function Errorhandle (obj,msg)
{
Alert (msg);
IsError = true;
Obj.focus ();
}
}
application Example:
function Chkform ()
{
var Form = document. Testform;
var Validator = new Validatorclass ();
Validator.chkname (Form.zd_username, "The name of the order is not lawful!");
Validator.chkemail (Form.zd_email, "The Order person mail address is illegal!");
Validator.chkplace (Form.zd_province, "the province of the ordering person is not lawful!");
Validator.chkplace (Form.zd_city, "Order people City Illegal!");
Validator.chkaddress (Form.zd_address, "The order person address is illegal!");
Validator.chkpostnumber (Form.zd_zip, "The order person postcode is not lawful!");
Validator.chkmobile (Form.zd_mobile, "Order person mobile phone is illegal!");
Validator.chkphone (Form.zd_phone, "the ordering person fixed telephone is illegal!");
Validator.submit (Form, "verify success!") ");
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.