简体   繁体   English

用于验证逗号分隔字符串的 JavaScript 正则表达式

[英]JavaScript regular expression for the validation of comma separated string

I want to validate whether the user enter data in this form B101,202,BBB,B902,Z-102 That is each value can be only of alphabets, digits or alphanumeric + '-' Tried this expression but it failed for alphabets and digits only condition.我想验证用户是否以这种形式输入数据B101,202,BBB,B902,Z-102即每个值只能是字母、数字或字母数字 + '-' 尝试过此表达式,但字母和数字失败唯一的条件。 ^[A-Za-z0-9]+(,[A-Za-z0-9]+)*[A-Za-z0-9]+$ ^[A-Za-z0-9]+(,[A-Za-z0-9]+)*[A-Za-z0-9]+$

Please try the following regex请尝试以下正则表达式

^[A-Z0-9]+((,|-)[A-Z0-9]+)*[A-Z0-9]+$

This checks the following:这会检查以下内容:

  • Starts with Alphabets or Numeric以字母或数字开头
  • Ends with Alphabets or Numeric以字母或数字结尾

You can try it online at Regexr.com您可以在Regexr.com上在线试用

This regex not woking with list of 1 digit numbers like 64,5,8,9此正则表达式不适用于 64、5、8、9 等 1 位数字的列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM