function
getByteLen (Val) {// pass a string
var len = 0 ; for ( var I = 0 ; I < val.length; I ++ ) { IF (Val [I] .match ( / [^ \ xOO - \ xFF] / IG) ! = null ) // a full- len + = 2 ; // If full-width, if mysql occupies two bytes is a field in the text, if the set encoded as utf-8, it is a Chinese 3 bytes, two bytes GBK the else len + = . 1 ; // half-size one byte } return len;
var len = 0 ; for ( var I = 0 ; I < val.length; I ++ ) { IF (Val [I] .match ( / [^ \ xOO - \ xFF] / IG) ! = null ) // a full- len + = 2 ; // If full-width, if mysql occupies two bytes is a field in the text, if the set encoded as utf-8, it is a Chinese 3 bytes, two bytes GBK the else len + = . 1 ; // half-size one byte } return len;
}
//transfer
if (getByteLen("追忆") < 3) {
alert ( "length of not less than three characters");
}else{
alert ( "Enter the correct");
}