Where can I find regular expressions for the datatypes defined in XSD?
The XSD specification includes regular expressions for the datatypes, however they doesn’t seem to be correct. For example, for xsd:float the suggested regular expression is (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?|(\+|-)?INF|NaN, which, however, matches even strings like “0.this is not a float”:
var floatRegex = /(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?|(\+|-)?INF|NaN/;
floatRegex.test("0.this is not a float"); # returns true
Am I missing something from the XSD specification? Is there other source of correct regular expressions for XSD datatypes (e.g., RegExLib.com doesn’t have them)?
If you don’t want to allow anything around, then add
^at the beginning and$at the end (with grouping):^( regex )$