<script> function check(obj){ if (obj.value.match(/^[-\u4e00-\u9fa5@()\/\*]+$/)) { alert(obj.value+" is well formed!"); } else { alert(obj.value+" is not well formed!"); obj.value = ""; } }
<script> function check(obj){ if (obj.value.match(/^[-\u4e00-\u9fa5@()\/\*]+$/)) { alert(obj.value+" is well formed!"); } else { alert(obj.value+" is not well formed!"); obj.value = ""; } } </script> <input type="text" onblur="check(this)"> </input>
只有出现不该出现的才返回false,只要出现的都属于允许字符就没问题
允许字母、数字、汉字及@,-,(),/,*,;等特殊字符出现 <script> function check(obj){ if (obj.value.match(/^[-\da-zA-Z\u4e00-\u9fa5@()\/\*]+$/)) { alert(obj.value+" is well formed!"); } else { alert(obj.value+" is not well formed!"); obj.value = ""; } } </script> <input type="text" onblur="check(this)" value="允许字母、数字、汉字及@,-,(),/,*,;等特殊字符出现"> </input>
楼主,那你就是只排除空格,换行符等特殊字符就可以了 <script> function check(obj){ if (obj.value.match(/^\S+$/)) { alert(obj.value+" is well formed!"); } else{ alert(obj.value+" is not well formed!"); obj.value = ""; } } </script>
function check(obj){
if (obj.value.match(/^[-\u4e00-\u9fa5@()\/\*]+$/)) {
alert(obj.value+" is well formed!");
}
else {
alert(obj.value+" is not well formed!");
obj.value = "";
}
}
</script>
<input type="text" onblur="check(this)"></input>
function check(obj){
if (obj.value.match(/^[-\u4e00-\u9fa5@()\/\*]+$/)) {
alert(obj.value+" is well formed!");
}
else {
alert(obj.value+" is not well formed!");
obj.value = "";
}
} </script>
<input type="text" onblur="check(this)"> </input>
只有出现不该出现的才返回false,只要出现的都属于允许字符就没问题
<script>
function check(obj){
if (obj.value.match(/^[-\da-zA-Z\u4e00-\u9fa5@()\/\*]+$/)) {
alert(obj.value+" is well formed!");
}
else {
alert(obj.value+" is not well formed!");
obj.value = "";
}
} </script>
<input type="text" onblur="check(this)" value="允许字母、数字、汉字及@,-,(),/,*,;等特殊字符出现"> </input>
<script>
function check(obj){
if (obj.value.match(/^\S+$/)) {
alert(obj.value+" is well formed!");
}
else{
alert(obj.value+" is not well formed!");
obj.value = "";
}
}
</script>
/^[0-9a-zA-Z\u4e00-\u9fa5\@\(\)\/\*\.\-\_](\;*[0-9a-zA-Z\u4e00-\u9fa5\@\(\)\/\*\.\-\_])*$/i;
原本后面是+$/i,可试的进候若输入单 个的字符则通不过,后来改成了这个。