<input type="text" id="tel">
<input type="button" value="提交" onClick="check()">
<input type="submit" value="清除首尾空格">
<script>
String.prototype.trim=function () {
return this.replace(/^\s+|\s+$/g,'');
}
function $ (id) {
return document.getElementById(id);
}
function check () {
var n=$ ('tel').value.trim ();
$ ('tel').value=n;
var p=/^([a-z]|[\u4e00-\u9fa5]){2,3}$/i;
alert(p.test(n));
}

 

<input type="button" value="提交" onClick="check()">
<input type="submit" value="清除全部空格">
<script>
String.prototype.trim=function  () {
    return this.replace(/\s/g,'');
}
function $ (id) {
    return document.getElementById(id);
}
function check () {
    var n=$ ('tel').value.trim ();
    $ ('tel').value=n;
    var p=/^([a-z]|[\u4e00-\u9fa5]){2,3}$/i;
    alert(p.test(n));
}


</script>

 

Copyright © 2024 小蕊同学
Powered by .NET 8.0 on Kubernetes