function pic_onsubmit()
{
tmptext1=eval("window.pic.bh.value");
for(l=0;l<tmptext1.length;l++)
{
ls=tmptext1.charCodeAt(l);
if ((ls<48) || (ls>122 && ls<128) || (ls>57 && ls<65)|| (ls<97 && ls>90))
{
alert("不属于字符和数字");
}
}
}
{
tmptext1=eval("window.pic.bh.value");
for(l=0;l<tmptext1.length;l++)
{
ls=tmptext1.charCodeAt(l);
if ((ls<48) || (ls>122 && ls<128) || (ls>57 && ls<65)|| (ls<97 && ls>90))
{
alert("不属于字符和数字");
}
}
}
byte[] tempbyte=validString.getBytes();
for(int i=0;i<validString.length();i++) {
//by=tempbyte[i];
if((tempbyte[i]<48)||(tempbyte[i]>57)){
return false;
}
}
return true;
}判断字符串是否为只包括字母和数字 public static boolean isChar(String validString){
byte[] tempbyte=validString.getBytes();
for(int i=0;i<validString.length();i++) {
// by=tempbyte[i];
if((tempbyte[i]<48)||((tempbyte[i]>57)&(tempbyte[i]<65))||(tempbyte[i]>122)||((tempbyte[i]>90)&(tempbyte[i]<97))) {
return false;
}
}
return true;
}
判断字符串是否只包括字母 public static boolean isLetter(String validString){
byte[] tempbyte=validString.getBytes();
for(int i=0;i<validString.length();i++) {
//by=tempbyte[i];
if((tempbyte[i]<65)||(tempbyte[i]>122)||((tempbyte[i]>90)&(tempbyte[i]<97))) {
return false;
}
}
return true;
}
static boolean isDigit(char ch) 判断一个字符是否数字
static boolean isLetter(char ch) 判断一个字符是否字母
static boolean isLetterOrDigit(char ch) 判断一个字符是否字母或数字
static boolean isLowerCase(char ch) 判断一个字符是否小写字母
static boolean isUpperCase(char ch) 判断一个字符是否大写字母
static boolean isWhitespace(char ch) 判断一个字符是否空格
还有很多其它的,可以自行参考JavaDoc
http://java.sun.com/j2se/1.4.2/docs/api/
java.util.regex.Pattern例如:
boolean b = Pattern.matches("a*b", "aaaaab");
就是判断第二个参数"aaaaab" 是不是第一个参数指定的模式a*b(代表以0个或多个a开头,以一个b结尾), 结果返回true.