js去除空格驗證不能爲空

<script language="javascript">
String.prototype.trim = function() {
 return this.replace(/(^\s*)|(\s*$)/g, "");
}
function check(){
  var v = aForm.bv.value;
  if(v.trim().length==0){
    alert("不能爲空!");
  }
}
</script>
</head>
<form name="aForm">
<input type="text" name="bv" />
<input type="button" name="jj" value="check" οnclick="check()" />
</form>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章