php - What regex can I use to validate a number between 0 and 255? -
i want validate number in range of 0-255
i have expression
'/^([0-1]?[0-9]?[0-9])|([2][0-4][0-9])|(25[0-5])$/' but accepts number... , works:
'/(^[0-1]?[0-9]?[0-9]$)|(^[2][0-4][0-9]$)|(^25[0-5]$)/' why have have ^ , $ each option?
edit: have it, cannot answer question, - ^ , $ have higher priority |, /^(...)$/ helped
note: @alex's answer way go. validating number range regex using jackhammer catch fly.
but nevertheless wanted provide explanation "problem".
you don't have to, have group correctly, means have group alternation:
'/^(([0-1]?[0-9]?[0-9])|([2][0-4][0-9])|(25[0-5]))$/' // ^ ^ otherwise expression interpreted follows (logically)
(^number) or (number) or (number$) with brackets, be
^(number or number or number)$
Comments
Post a Comment