HTML5 Form Validator Support Product Page

Not a problem

Pattern matching with RegEx

Reported 16 Aug 2016 14:35:36
has this problem
16 Aug 2016 14:35:36 David Woolley posted:
I'm having trouble using pattern matching with RegEx for client-side validation. No problem with the other validations so far.
I need to make sure users search for a particular pattern in a code - 4 digits that can include leading zeros for example: 0004 , 0104

I thought that this expression would do it: \d{4}
but no validation occurs. \d\d\d\d lets everything thru as well.
Then I tried quite a few other simple regexes to test the system but all entries are accepted.


Replied 17 Aug 2016 09:29:54
17 Aug 2016 09:29:54 Teodor Kuduschiev replied:
Hi David,
As per your pattern you should use: (^([0-9]{4})$)
Replied 22 Aug 2016 11:59:13
22 Aug 2016 11:59:13 David Woolley replied:
Hi Teodor

(^([0-9]{4})$) or ^[0-9]{4}$ still lets anything thru.
For example I can enter "xyz" and the input field does not reject with an error message.

As I said earlier, I've also tested a few other simple regexes with this input field and nothing is rejected.

Number Validation validates perfectly, but obviously with no leading zeros.
Replied 22 Aug 2016 12:08:55
22 Aug 2016 12:08:55 Teodor Kuduschiev replied:
Hello David,
With the validation pattern i provided "xyz" does not get through ....

Replied 22 Aug 2016 12:44:29
22 Aug 2016 12:44:29 David Woolley replied:
Thanks Teodor - working now.
In all my troubleshooting, I managed to delete the type = "text" attribute.
Added this back then it validates. But if the input tag does not have a type attribute, it should default to "text" anyway.
Replied 06 Aug 2023 20:06:27
06 Aug 2023 20:06:27 Mike Anderson replied:
Pattern matching with RegEx (Regular Expressions) allows you to search for specific patterns within text or data. By using RegEx, you can find and extract information that matches a certain pattern, helping in tasks like data validation and text parsing. To sell art as an NFT, create a digital wallet on a reputable NFT marketplace. Then, mint your artwork as an NFT by uploading it to the platform and adding relevant details and metadata. Finally, list your NFT for sale, setting a price and waiting for potential buyers to make a purchase using cryptocurrency.

Reply to this topic