Regular Expression batch verification functions

Source: Internet
Author: User
Regular Expression batch verification functions

Function checkdata (){
// Determine the correctness of the data
VaR idspans = new array ();
Idspans [0] = new array ("item_4", "^ [\ s] {1, 16} $", "productname ", "The business opportunity name should be 1-16 characters or less", "Idspans [1] = new array ("item_5", "^ [\ s] {1, 16} $", "ptitle ", "The business opportunity title should be 1-16 characters or less", "Idspans [2] = new array ("item_3_2", "^ [\ s] + $", "iditem_3_2spans", "Business Opportunity category cannot be blank ", "Idspans [3] = new array ("item_7", "^ [\ s] + $", "iditem_7spans", "product series cannot be blank ", "Idspans [4] = new array ("item_8_1", "^ [\ s] {2, 30} $", "iditem_8_1spans ", "The business opportunity must be 2-30 characters in length", "Idspans [5] = new array ("item_8_2", "^ [\ s] {2, 30} $", "iditem_8_1spans ", "The business opportunity must be 2-30 characters in length", "Idspans [6] = new array ("item_8_4", "^ [\ D] + $", "iditem_8_4spans", "Business Opportunity quantity is in digital format ", "Idspans [7] = new array ("item_8_6", "^ [0-9] + [\.]? [0-9] * $ "," iditem_8_6spans "," the unit price can only consist of numbers and decimal places !! "," ", false );
// Idspans [8] = new array ("item_9", "^ [\ s] {16 ,}$", "iditem_9spans ", "The description cannot be less than 16 characters", "// Idspans [9] = new array ("item_1_1", "^ [\ s] + $", "iditem_1_1spans", "Business Opportunity image cannot be blank ", "

VaR reg;
VaR textvalue;
For (VAR I = 0; I <idspans. length; I ++)
{
Reg = new Regexp (idspans [I] [1], "IgM ");
Textvalue = Document. getelementbyid (idspans [I] [0]). value;
If (textvalue. length> 0 | idspans [I] [5])
{
If (Reg. Test (textvalue ))
{
Document. getelementbyid (idspans [I] [2]). innerhtml = "<font color = 'green'>" + idspans [I] [4] + "</font> ";
}
Else
{
Try
{
Document. getelementbyid (idspans [I] [0]). Focus ();
}
Catch (E)
{

}
Document. getelementbyid (idspans [I] [2]). innerhtml = "<font color = 'red'>" + idspans [I] [3] + "</font> ";
Return false;
}
Alert (textvalue );
}
}
// Alert (document. getelementbyid ('item _ 3_2 '). Options. Length );
If (document. getelementbyid ('item _ 3_3 '). Options. length> 0 & document. getelementbyid ('item _ 3_3'). selectedindex <0)
{
Document. getelementbyid ("iditem_3_2spans"). innerhtml = "the last category should be selected! ";
Document. getelementbyid ("item_3_3"). Focus ();
Return false;
}
Return true;
}

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.