簡體   English   中英

在JS中使用正則表達式進行字符串驗證

[英]String validation with regex in JS

我需要幫助來構造正則表達式以驗證Javascript中的字符串格式,

字符串的總長度應在3到30個字符之間。 第一個字符必須嚴格是字母。 后續字符可以是字母,點或空格。 請幫忙。

以下將為您工作。

var re = /^[a-z][a-z. ]{2,29}$/i

正則表達式:

^                # the beginning of the string
 [a-z]           # any character of: 'a' to 'z'
 [a-z. ]{2,29}   # any character of: 'a' to 'z', '.', ' ' (between 2 and 29 times)
$                # before an optional \n, and the end of the string

暫無
暫無

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

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