How to check for ma 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()">
How to check for ma 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()">
Share
Improve this question
edited Jul 30, 2022 at 20:54
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Mar 25, 2010 at 7:06
HulkHulk
34.2k64 gold badges150 silver badges217 bronze badges
3 Answers
Reset to default 3/^[A-Za-z](?:,[A-Za-z])*$/.test(document.getElementById("val").value)
You should use a csv library for validating, one of the good ones out there is http://papaparse./
var val = document.getElementById('val').value;
var results = Papa.parse(csvString, config)
var errors = results["errors"]
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 a 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()">