开发者

How to test Text Field Validate a comma exists in a field

How开发者_如何学Python to test input Field Validate a comma exists in a input field ?


var value = document.getElementById('id-of-the-form-field').value 
// or: var value = document.getElementsByName('name-of-the-form-field')[0].value

if(value.indexOf(',') > -1) {
    // value contains a comma
}

If this is not what you want, you have to give more details.

Reference: .indexOf()


str = document.getElementById(text_feild_id).value
arr = str.split(",")
if (arr.length>1){
  alert("comma exist");
}

or

   if (str.replace(/[^,]/g, "").length>=1){
      alert("comma exist");
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜