3

How to check for comma separated values in a text box and raise an alert if not found? And if there is it should be characters in it like A,B,C,D

  function validate()
   {
         //validate text box;
   }
  <input type="text" id="val" >A,B,C,D</input>
  <input type="button" id="save" onclick="validate()">  
 

3 Answers 3

3
/^[A-Za-z](?:,[A-Za-z])*$/.test(document.getElementById("val").value)
Sign up to request clarification or add additional context in comments.

Comments

2

You should use a csv library for validating, one of the good ones out there is http://papaparse.com/

var  val = document.getElementById('val').value;
var results = Papa.parse(csvString, config)
var errors = results["errors"] 

Comments

1

I hope this will help you

function validate()
{
    val = document.getElementById('val').value;
    val = val.split(',');
    alert(val[0].length);
    for(var i=0;i<val.length;i++)
    {
        if(val[i].length != 1){
            alert("Please check value should be coma seperated at every single characters");
            return false;
        }
    }
    return true; 
}

HTML:

<input type="text" id="val" value = 'A,B,C,D' ></input>
<input type="button" id="save" onclick="return validate()">  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.