tags:

views:

23

answers:

2

How to test input Field Validate a comma exists in a input field ?

A: 
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()

Felix Kling
A: 
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");
    }
Salil