Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Regex - Negative match

Tags:

regex

xml

xsd

I have a problem with negative lookahead in XSD pattern. When I specified:

<xs:pattern value="^(?!(00|\+\d))\d{6,}$"/>

then I got an error message:

Value '^(?!(00|\+\d))\d{6,}$' is not a valid XML regular expression.

Any idea why it does not work?

In online javascript validator it works fine (e.g. here under unit tests section click on "run test").

I need to validate phone numbers. The phone number cannot include international prefixes (+\d) and (00).

Thanks

like image 694
peterko Avatar asked Apr 16 '26 06:04

peterko


1 Answers

Try the following regex:

[1-9][0-9]{5,} | 0[1-9][0-9]{4,}

This matches a number which does not begin with zero and is followed by any digit (including zero) 5 or more times, and it also matches a number which starts with zero and is not immediately followed by zero, but after that can have 0-9.

like image 77
Tim Biegeleisen Avatar answered Apr 20 '26 15:04

Tim Biegeleisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!