Reputation: 1450
How can I validate the last digits of URL /?d=123
the URL will always ends with /?d=(no more than 4 numbers) ex.12345 will never appear
http://www.test.com/?d=123
This is what i have, but I don't know how to match just the ones that end with 123
and 4321
(http(s)?://)([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?
Upvotes: 0
Views: 193
Reputation: 4981
Regex to validate a URL for which the query parameter contains only digits (1 to 4 like OP suggested):
^(http(s)?://)([\w-]+.)+[\w-]+([\w- ;,./%&=]*)\?((\w)+=(\d){1,4})$
Regex to validate a URL for which query parameters are either 123 or 4321:
^(http(s)?://)([\w-]+.)+[\w-]+([\w- ;,./%&=]*)\?((\w)+=(123|4321))$
EDIT: Minor modifications as per OP's requirements and @Stephen P's suggestions
Upvotes: 2