Verification: Non-empty, mobile phone number, mailbox

Source: Internet
Author: User

1         /// <summary>2         ///Verify non-null3         /// </summary>4         /// <param name= "IsOK" ></param>5         /// <param name= "Cons" ></param>6         Private voidCheckcontrols (ref BOOLIsOK,paramscontrol[] cons)7         {8             9             foreach(Control coninchcons)Ten             { One                 //non-null validation A                 if(Con isTextBox) -                 { -                     if(Con. Text.trim (). Length <=0) the                     { -Con. BackColor =System.Drawing.Color.Red; -IsOK =false; -                     } +                     Else -                     { +Con. BackColor =System.Drawing.Color.White; A                     } at                 } -             } -}

1         /// <summary>2         ///Save3         /// </summary>4         /// <param name= "Sender" ></param>5         /// <param name= "E" ></param>6         Private voidBtnsave_click (Objectsender, EventArgs e)7         {8             #regionVerify non-null9             //Verify non-nullTen             BOOLIsOk =true; OneCheckcontrols (refisOk, Txtmobile, Txtpwd, txtusername); A             if(!isOk) -             { -                 return; the             }  -             #endregion -  -             #regionVerify that the user name already exists +             //Verify that the user name already exists -             stringUsername =TxtUserName.Text.Trim (); +UserInfo user1 =Userbll.getuserinfobyusername (username); A             if(User1! =NULL) at             { -Lbusername.text ="user name already exists"; -                 return; -             } -Lbusername.text =""; -             #endregion in  -             #regionVerify Password strength to             //Verify Password Strength +             if(TxtPwd.Text.Trim (). Length <6) -             { theLbpwd.text ="password at least six digits or English alphabet"; *                 return; $             }Panax NotoginsengLbpwd.text =""; -             #endregion the  +             #regionVerify your phone number A             //Verify your phone number the             //must be 11 bits, must be 1 start, must each digit is a number +             if(TxtMobile.Text.Trim (). Length! = One) -             { $Lbmobile.text ="must be 11-bit"; $                 return; -             } -             if(TxtMobile.Text.Substring (0,1) !="1") the             { -Lbmobile.text ="must start with 1";Wuyi                 return; the             } -             foreach(CharChinchLbMobile.Text.Trim (). ToCharArray ()) Wu             { -                 if(!Char. IsDigit (CH)) About                 { $Lbmobile.text ="must be all numbers ."; -                     return; -                 } -             } ALbmobile.text ="";  +             #endregion the  -             #regionVerify Mailbox $             //Verify Mailbox the             if(TxtEmail.Text.Trim (). Length>0) the             { the                 //[0-9a-za-z_.-][email protected][0-9z-za-z_.-]+ ([.] [A-za-z]) {A} the                 //^[a-z0-9]+ ([. _\\-]*[a-z0-9]) *@ ([a-z0-9]+[-a-z0-9]*[a-z0-9]+.) {1,63} [A-z0-9]+$ -                 stringReg ="^[a-z0-9]+ ([. _\\-]*[a-z0-9]) *@ ([a-z0-9]+[-a-z0-9]*[a-z0-9]+.) {1,63} [A-z0-9]+$"; in                 if(!Regex.IsMatch (TxtEmail.Text.Trim (), Reg)) the                 { theLbemail.text ="Please enter a mailbox that meets the mailbox format"; About                     return; the                 } the             } theLbemail.text ="";  +             #endregion -  the             //Assign ValueBayiUserInfo user =NewUserInfo (); theUser. Address =Txtaddress.text; theUser. Email =Txtemail.text; -User. Mobile =Txtmobile.text; -User. PWD = Encryptpwd.encryptpassword (Txtpwd.text + encryptpwd.getpwdsalt ());//(password + password salt) before encryption theUser. UserName =txtUsername.Text; theUser. Gender = rdomale.checked?1:2;//RDO must have limited and only one selected the             BOOLFlag =false; the             if( This. Isadd = =1)//New -             { the                 //New theFlag =userbll.insertuserinfo (user); the             }94             Else if( This. Isadd = =2)//Edit the             { theUser. Id =Convert.ToInt32 (lbid.text); theFlag =userbll.updateuserinfo (user);98             } About             Else -             {101                 Throw NewException ("Unknown Isadd value:"+ This. Isadd);102             }103             stringmsg = flag?"Operation succeeded":"operation failed";104 MessageBox.Show (msg); the             //DialogResult = DialogResult.OK;106              This. Close ();107}

Verification: Non-empty, mobile phone number, mailbox

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.