Flash uses regular expressions for registration verification

Source: Internet
Author: User
The person who writes the registration page in Asp.net will be excited by the verification controls provided by. net. It provides powerful functions .. Net has built-in common regular expressions, which are very convenient to use.
However, if you want to complete the registration page in flash, the tedious user name, password, and other judgments can only be written by ourselves.
Well, let's first look at the effect:
Then the expression class Regexp. Class: Oh ~ It's too long. I just need to upload an attachment directly.
Username, PWD, ID, email, and homepage are textinput components;
Usernamefalse, pwdfalse, idfalse, emailfalse, and homepagefalse are MC
For Regexp. Class usage tips, "\" is represented by double backslice bars "\". In this form, it can prevent the parser from starting as an escape sequence.
Specific implementation:
VaR txtlistener: Object = new object ();
Txtlistener. focusout = function (evt_obj: Object ){
Switch (evt_obj.tar get ){
Case Username:
// A string consisting of digits, 26 English letters, or underscores
VaR EX = "^ \ W + $ ";
VaR Re = new Regexp (ex, "G ");
Trace ("username changed ");
If (Re. Test (username. Text )){
Usernamefalse. _ visible = false;
} Else {
Usernamefalse. _ visible = true;
}
Break;
Case PWD:
// A string consisting of digits, 26 English letters, or underscores
VaR EX = "^ \ W + $ ";
VaR Re = new Regexp (ex, "I ");
Trace (Re. Test (PWD. Text ));
Trace ("PWD changed ");
If (Re. Test (PWD. Text )){
Pwdfalse. _ visible = false;
} Else {
Pwdfalse. _ visible = true;
}
Break;
Case ID:
VaR EX = "\ D {17} [\ d | x] | \ D {15 }";
VaR Re = new Regexp (ex, "I ");
Trace (Re. Test (Id. Text ));
Trace ("ID changed ");
If (Re. Test (Id. Text )){
Idfalse. _ visible = false;
} Else {
Idfalse. _ visible = true;
}
Break;
Case Email:
VaR EX = "\ W + ([-+. '] \ W +) * @ \ W + ([-.] \ W + )*\\. \ W + ([-.] \ W + )*";
VaR Re = new Regexp (ex, "I ");
Trace (Re. Test (email. Text ));
Trace ("email changed ");
If (Re. Test (email. Text )){
Emailfalse. _ visible = false;
} Else {
Emailfalse. _ visible = true;
}
Break;
Case homepage:
VaR EX = "HTTP (s )? : // ([\ W-] + \.) + [\ W-] + (/[\ W -./? % & =] *)? ";
VaR Re = new Regexp (ex, "I ");
Trace (Re. Test (homepage. Text ));
Trace ("homepage changed ");
If (Re. Test (homepage. Text )){
Homepagefalse. _ visible = false;
} Else {
Homepagefalse. _ visible = true;
}
Break;
}
};
// Addeventlistener
Username. addeventlistener ("focusout", txtlistener );
PWD. addeventlistener ("focusout", txtlistener );
Id. addeventlistener ("focusout", txtlistener );
Email. addeventlistener ("focusout", txtlistener );
Homepage. addeventlistener ("focusout", txtlistener );
//////////////////////////////////////// //////////
// The visual value of each error prompt in the initial state is false;
Usernamefalse. _ visible = false;
Pwdfalse. _ visible = false;
Idfalse. _ visible = false;
Emailfalse. _ visible = false;
Homepagefalse. _ visible = false;

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.