Here's an example of how one might validate email using ActionScript 3's Regular Expression class (Top level RegExp):
ActionScript Code:
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(email);
}
//...
trace(isValidEmail("senocular@example.com")); // true
trace(isValidEmail("@example.com")); // false
trace(isValidEmail("senocular@example")); // false
trace(isValidEmail("seno\\cular@example.com")); // false
1评论:
//是否为Double型数据;
public static function isDouble(char:String):Boolean {
char = trim(char);
var pattern:RegExp = /^[-\+]?\d+(\.\d+)?$/;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//Integer;
public static function isInteger(char:String):Boolean {
if (char == null) {
return false;
}
char = trim(char);
var pattern:RegExp = /^[-\+]?\d+$/;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//English;
public static function isEnglish(char:String):Boolean {
if (char == null) {
return false;
}
char = trim(char);
var pattern:RegExp = /^[A-Za-z]+$/;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//中文;
public static function isChinese(char:String):Boolean {
if (char == null) {
return false;
}
char = trim(char);
var pattern:RegExp = /^[\u0391-\uFFE5]+$/; ;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//双字节
public static function isDoubleChar(char:String):Boolean {
if (char == null) {
return false;
}
char = trim(char);
var pattern:RegExp = /^[^\x00-\xff]+$/;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//含有中文字符
public static function hasChineseChar(char:String):Boolean {
if (char == null) {
return false;
}
char = trim(char);
var pattern:RegExp = /[^\x00-\xff]/;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//注册字符;
public static function hasAccountChar(char:String,len:uint=15):Boolean {
if (char == null) {
return false;
}
if (len < 10) {
len = 15;
}
char = trim(char);
var pattern:RegExp = new RegExp("^[a-zA-Z0-9][a-zA-Z0-9_-]{0,"+len+"}$", "");
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
//URL地址;
public static function isURL(char:String):Boolean {
if (char == null) {
return false;
}
char = trim(char).toLowerCase();
var pattern:RegExp = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
var result:Object = pattern.exec(char);
if (result == null) {
return false;
}
return true;
}
发表评论