I need a regular expression to validate a web form field that should contain an AS number in asdot notation as explained in RFC 5396:
asdot
refers to a syntax scheme of representing AS number values less than 65536 using asplain notation and representing AS number values equal to or greater than 65536 using asdot+ notation. Using asdot notation, an AS number of value 65526 would be represented as the string "65526" and an AS number of value 65546 would be represented as the string "1.10".
I want to use Javascript RegExp object and Java EE javax.validation.constraints.Pattern with regex.
Here’s a Javascript regex that should do what you require:
Assumptions:
Numbers beginning
0.are disallowed.Numbers with a zero after the dot are allowed as I presume e.g. that
65536is represented as1.0.Leading zeros are not allowed in the number after the dot e.g.
1.00009is invalid.The maximum value of a 4-byte AS number is
4294967295which is65536*65535 + 65535, i.e.65535.65535in asdot notation.As Javascript RegExp oject:
As Java Pattern: