JS: trim () in Javascript, how to define a function of checkinput for a webcontrol (ascx)

Source: Internet
Author: User

// Remove spaces at both ends of the string. The usage is string. Trim ()
String. Prototype. Trim = function ()
{
Return this. Replace (/(^/S *) | (/S * $)/g ,"");
}

Function checkinput ()
{
// Verification name
Document. form1.addmessage1 _ messagetitle. value = Document. form1.addmessage1 _ messagetitle. value. Trim ();
If (document. form1.addmessage1 _ messagetitle. value = "")
{
Alert ("Enter the Message Title ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ messagetitle. Focus ();
Return false;
}
 
// Verify the message content
Document. form1.addmessage1 _ content. value = Document. form1.addmessage1 _ content. value. Trim ();
If (document. form1.addmessage1 _ content. value = "")
{
Alert ("Enter the message content ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ content. Focus ();
Return false;
}
// Verify the input length
If (document. form1.addmessage1 _ content. value. length> 1000)
{
Alert ("the detailed description of the project you entered is too long. You can enter up to 1000 words ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ content. Focus ();
Return false;
}
// Verify the contact name
Document. form1.addmessage1 _ leaveman. value = Document. form1.addmessage1 _ leaveman. value. Trim ();
If (document. form1.addmessage1 _ leaveman. value = "")
{
Alert ("enter your name ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ leaveman. Focus ();
Return false;
}
 
 
// Verify the mobile phone number
Document. form1.addmessage1 _ mobile. value = Document. form1.addmessage1 _ mobile. value. Trim ();
/* If (document. form1.addmessage1 _ msgmobile. value = "")
{
Alert ("Enter your mobile phone number ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ msgmobile. Focus ();
Return false;
}*/
// Verify the validity of the mobile phone number
/* Rege =/^ 13/d {9} $ /;
If (! Rege. Test (document. form1.addmessage1 _ msgmobile. Value ))
{
Alert ("invalid mobile phone number ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ msgmobile. Focus ();
Return false;
}
*/
// Phone number
Document. form1.addmessage1 _ phone. value = Document. form1.addmessage1 _ phone. value. Trim ();
If (document. form1.addmessage1 _ phone. value = "")
{
Alert ("Enter your phone number ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ phone. Focus ();
Return false;
} Else
{
If (! Document. form1.addmessage1 _ phone. value. length> 7)
{
Alert ("the number of phone numbers you entered is incorrect! ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ phone. Focus ();
Return false;
}
}
// Contact address
Document. form1.addmessage1 _ contactaddress. value = Document. form1.addmessage1 _ contactaddress. value. Trim ();
If (document. form1.addmessage1 _ contactaddress. value = "")
{
Alert ("Enter the contact address ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ contactaddress. Focus ();
Return false;
}
// Zip code
Document. form1.addmessage1 _ postcode. value = Document. form1.addmessage1 _ postcode. value. Trim ();
If (document. form1.addmessage1 _ postcode. value = "")
{
Alert ("Enter the zip code ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ postcode. Focus ();
Return false;
}
// QQ
Document. form1.addmessage1 _ QQ. value = Document. form1.addmessage1 _ QQ. value. Trim ();
// Msn
Document. form1.addmessage1 _ MSN. value = Document. form1.addmessage1 _ MSN. value. Trim ();
If (document. form1.addmessage1 _ MSN. value = "")
{
/* Alert ("Enter the MSN address ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ msgmsn. Focus ();
Return false ;*/
}
Else
{
Rege =/^ ([a-zA-Z0-9] + [_ |/-|/.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ |/-|/.]?) * [A-zA-Z0-9] +/. [A-Za-Z] {2, 3} $ /;
/* If (! Rege. Test (document. form1.msn. Value ))
{
Alert ("invalid MSN address ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.msn. Focus ();
Return false;
}*/
}
// Email
Document. form1.addmessage1 _ email. value = Document. form1.addmessage1 _ email. value. Trim ();

If (document. form1.addmessage1 _ email. value = "")
{
/* Alert ("Enter the e_mail address ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ email. Focus ();
Return false ;*/
}
Else
{
Rege =/^ ([a-zA-Z0-9] + [_ |/-|/.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ |/-|/.]?) * [A-zA-Z0-9] +/. [A-Za-Z] {2, 3} $ /;
If (! Rege. Test (document. form1.addmessage1 _ email. Value ))
{
Alert ("invalid email address ");
Event. cancelbubble = true;
Event. returnvalue = false;
Document. form1.addmessage1 _ email. Focus ();
Return false;
}
}
 
}

Related Article

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.