Reputation: 2445
I'm using antd form item and I tried the below pattern but it's not working.
rules: [{
pattern: new RegExp("^d{4}-d{2}-d{4}$"),
message: "Please check format"
}]
Upvotes: 2
Views: 506
Reputation: 13964
You have to specify the digits as \d
and not just d
. Also, you can use a literal expression like this:
pattern: /^\d{4}-\d{2}-\d{4}$/
Or define it as a string passed to the RegExp constructor but you will have to escape the backslashes, leading to \\d
instead of \d
:
pattern: new RegExp('^\\d{4}-\\d{2}-\\d{4}$')
You can use a tool like Regex101 to help build and validate your regular expressions.
Upvotes: 1