簡體   English   中英

JQuery正則表達式接受字母數字字符和', -

[英]JQuery Regular expression to accept alphanumeric characters and ' , -

我正在試圖找出如何使我的正則表達式接受某些特殊字符: ' ,-以及字母數字字符。 我有一個刺,但無濟於事,我對正則表達式很新,有人可以幫忙嗎?

這是我的嘗試,令人驚訝的是,它不起作用......

/^\d+/,\'\-\$/i

像這樣的東西?

/[0-9a-zA-Z',-]+/

如果它必須是一個完整的字符串,你可以使用

/^[0-9a-zA-Z',-]+$/

嘗試

/^[\w',-]*$/

(假設您的意思是ASCII字母,數字和下划線“字母數字”)。

\\d[0-9]簡寫,不是任何字母數字字符。

/^[\w,'-]+$/i

應該做的伎倆。

這是說什么:

^ - match the start of the line
[ - match any of the following characters (group #1)
    \w - any word (meaning differs depending on locale;
         generally, any letter, number or the `-` character.)
    ,  - a comma
    '  - an apostrophe
    -  - a dash
] - end group #1
+ - one or more times
$ - match the end of the line
/i - set case-insensitivity.

暫無
暫無

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

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