最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - JavaScript CSV validation - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

3 Answers 3

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()">  
发布评论

评论列表(0)

  1. 暂无评论