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");
}
精彩评论