1.在前端(SWT)表单页面,经常会使用验证,非空的验证,太简单,代码不贴了。验证只能是字母(不区分大小写)、数字、汉字的正则表达式以及验证的代码如下:
private boolean valiOrganName(){
String organName="test";
//包含数字、字母(不区分大小写)、汉字的正则表达式,这里还限制了长度1~16
String regex="^[\\u4E00-\\u9FA5\\uF900-\\uFA2D\\w]{1,16}$";
return matches(regex, organName);
}
/**
*
* @Title: matches
* @Description: 验证inputValue是否符合正则表达式regex,符合返回true,不符合返回false
* @param regex
* @param inputValue
* @return boolean
*/
public boolean matches(String regex, String inputValue) {
Pattern pattern = Pattern.compile(regex);
return pattern.matcher(inputValue).matches();
}
本文介绍如何使用正则表达式在前端表单中进行验证,包括字母、数字、汉字的验证,以及长度限制。通过提供的示例代码,详细解释了如何实现这些验证逻辑。
682

被折叠的 条评论
为什么被折叠?



