有关正则表达式
1.只能输入数字和英文的:
<input οnkeyup="value=value.replace(/[\w]/g,'') " onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))" id="text1" name="text1">
2.只能输入数字的:
<input οnkeyup="value=value.replace(/[^\d]/g,'') " onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))" id="text2" name="text2">
3.只能输入全角的:
<input οnkeyup="value=value.replace(/[^\uff00-\uffff]/g,'')" onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\uff00-\uffff]/g,''))" id="text3" name="text3">
4.只能输入汉字的:
<input οnkeyup="value=value.replace(/[^\u4e00-\u9fa5]/g,'')" onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\u4e00-\u9fa5]/g,''))" id="text4" name="text4">
只要英文.数字.下划线的括号的话是
/[a-z\d_\(\)]/gi
public class tst {
public static void main(String arg[]){
String str="撒播";
String str2="2gf_FDHDFdgfd";
String str3="2gf撒fd";
System.out.println(str.matches("^[a-zA-Z_()\\d]+$"));
System.out.println(str.matches("^[^\\u4e00-\\u9fa5]+$"));
System.out.println(str2.matches("^[a-zA-Z_()\\d]+$"));
System.out.println(str2.matches("^[^\\u4e00-\\u9fa5]+$"));
System.out.println(str3.matches("^[a-zA-Z_()\\d]+$"));
System.out.println(str3.matches("^[^\\u4e00-\\u9fa5]+$"));
}
}