gpt4 book ai didi

javascript - 验证文本区域中逗号分隔词的字符数

转载 作者:行者123 更新时间:2023-11-29 21:03:31 25 4
gpt4 key购买 nike

我正在尝试验证在文本区域中输入的值,用户是否在逗号分隔值内输入了有效的十位数,例如

9876543210,98766543211,98766543212

如果用户输入的数字多于或少于 10 位,则必须提示错误。

到目前为止我已经尝试过类似的东西

$("#myMso").keyup(function(){
var value = $(this).val().replace(" ", "");
var word = value.split(",");

var lengths = words.map(function(word) {
if(lengths != 10){
alert("Hey! some of the contact number you have entered is not valid");
}
});
});

最佳答案

这样试试

   $("#myMso").keyup(function(){
var value = $(this).val();
var word = value.split(",");
$.each(word,function (key,value) {
if(value.length != 10){
alert("Hey! some of the contact number you have entered is not valid");
}

});
});

修改 on-change 事件:-

 $("#myMso").on('change',function(){
var value = $(this).val();
var word = value.split(",");
$.each(word,function (key,value) {
if(value.length != 10){
alert("Hey! some of the contact number you have entered is not valid");
}

});
});

关于javascript - 验证文本区域中逗号分隔词的字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45347319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com