Public classRegularutil { Public StaticBoolean checkname (Activity context, String name) {if(Textutils.isempty (name) | | name.length () <3|| Name.length () > -|| !NameFormat (name)) {Appmsg.maketext (context,"nickname does not conform to specification, 3-16 Chinese characters, numbers", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean checkheight (Activity context,intheight) { if(Height < -|| Height > -) {Appmsg.maketext (context,"height beyond normal range", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean checkweight (Activity context,intweight) { if(Weight < +|| Weight > -) {Appmsg.maketext (context,"weight beyond normal range", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean checkstepsize (Activity context,intstepsize) { if(Stepsize < -|| Stepsize > Max) {Appmsg.maketext (context,"Step beyond normal range", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean Checkemail (Activity context, String email) {if(!emailformat (email) | | email.length () > to) {Appmsg.maketext (context,"The mailbox format is not correct", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean Checkpassword (Activity context, String password) {if(!passwordformat (password)) {Appmsg.maketext (context,"The password format is 6-15-bit English characters, numbers", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean Checkpassword (Activity context, string password, string confirm) {if(!Checkpassword (context, password)) { return false; } if(!password.equals (confirm)) {Appmsg.maketext (context,"Inconsistent login password settings"); return false; } return true; } Public StaticBoolean Checkcode (Activity context, String code) {if(Code.length ()! =4) {Appmsg.maketext (context,"Please enter the correct four-digit verification code", Appmsg.style_alert). Show (); return false; } return true; } Public StaticBoolean Check (Activity context, string email, string password) {if(!emailformat (email) | | email.length () > to) {Appmsg.maketext (context,"The mailbox format is not correct", Appmsg.style_alert). Show (); return false; } if(!Checkpassword (context, password)) { return false; } return true; } Private Staticboolean Emailformat (String email) {Pattern pattern= Pattern.compile ("^[a-za-z\\d]+ (\\.[ a-za-z\\d]+) *@ ([\\dA-Za-z] (-[\\da-za-z])?) +(\\. {A} [a-za-z]+] +$"); Matcher MC=pattern.matcher (email); returnmc.matches (); } /** * start with a letter, length between 3~16, can only contain characters, numbers and underscores (w) * * @param password * @return*/ Private Staticboolean passwordformat (String password) {pattern pattern= Pattern.compile ("^[\\@a-za-z0-9\\!\\#\\$\\%\\^\\&\\*\\.\\~]{6,15}$"); Matcher MC=pattern.matcher (password); returnmc.matches (); } Public Staticboolean NameFormat (String name) {Pattern pattern= Pattern.compile ("^[\u4e00-\u9fa5a-za-z0-9_]{3,16}$"); Matcher MC=Pattern.matcher (name); returnmc.matches (); } /** * Get string byte length with double-byte characters * * @param s * @return*/ Public Static intGetstringlength (String s) {Char[] chars =S.tochararray (); intCount =0; for(Charc:chars) {Count+=Getspecialcharlength (c); } returncount; } /** * Get character length: han, Japanese, Korean character length is 2,ascii code and other characters length of 1 * * @param c * character * @return character length*/ Private Static intGetspecialcharlength (Charc) {if(Isletter (c)) {return 1; } Else { return 2; } } /** * To determine if a character is a ascill character or other character (such as Han, Japanese, Korean characters) * * @param char C, the character that needs to be judged * @return Boolean, return True,ascill character */ Private StaticBoolean Isletter (Charc) {intK =0x80; returnc/k = =0?true:false; }}
Android Authentication One