我怎样才能使正则表达式模式允许以下characters, numbers, white space, double quotes, ?, !, commas, hyphen, dots, @ and &
<textarea
id="comments"
type="textarea"
placeholder='comments'
{...register("comments", {
required: true,
minLength: {
value: 5,
message: "Minimum length of 5 letters"
},
pattern: {
value: /^[a-z0-9]+$/i,
message: "Supports characters, numbers, white space, "", ?, !, @, & and commas"
}
})}
>
</textarea>
1条答案
按热度按时间idfiyjo81#
变更
到
\s
是空格,-
需要转义,这样它就不会被视为范围分隔符。其余的只是您希望允许的其他字符。