簡體   English   中英

什么是javascript正則表達式來驗證字符串值數組

[英]what is javascript regex to validate an array of string value

我想使用正則表達式驗證字符串類型的單個元素的數組。 數組不能為空,並且不能以任何特殊符號開頭(#除外),並且字符串只能包含數字和字母。

我嘗試了什么[a-zA-z0-9s!@#$%^&*()_ / \\ + =。,〜`] +

你可以試試

regex = /^#?[a-zA-Z0-9]+/gm;

嘗試這個:

regex = /^#?[a-z0-9]+/gi;

分解:

/^ - Match the start of the string
#? - Match an optional #
[a-z0-9] - Character set including the lowercase alphabet, and all ten digits
+ - Match one or more of the preceding character set
/gi - Global and case-insensitive flags

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM