问题
I need to enforce the pattern LASTNAME/FIRSTNAME Something like Smith/John.
The characters can be Alphanumeric (lowercase/uppercase) also includes special characters like ë etc.
Pattern:
<xsd:pattern value="[a-zA-Z0-9]/[a-zA-Z0-9]"/>
Basically the rules will be - Anything before the slash - Anything after the slash - Patterns like "/John", "John/" should not be allowed
Thanks in advance.
回答1:
ASCII
Assuming that you don't want numbers in the names:
<xs:pattern value="[a-zA-Z]+/[a-zA-Z]+"/>
If you really want to accept numbers in the names:
<xs:pattern value="[a-zA-Z0-9]+/[a-zA-Z0-9]+"/>
Be aware that 0/0
, for example, would be valid in this case, though.
Unicode
<xs:pattern value="\p{L}+/\p{L}+"/>
Explanation: \p{L}
matches a Unicode code point in the Letter category.
回答2:
Your restriction should be this..
<xs:pattern value="(([a-zA-Z0-9])*)([/])(([a-zA-Z0-9])*)"/>
I validated this pattern by XMLSpear
来源:https://stackoverflow.com/questions/26176792/xsd-validation-pattern-to-enforce-lastname-firstname