XSD Validation Pattern to Enforce LastName/FirstNa

2019-07-04 01:03发布

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.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-04 01:51

Your restriction should be this..

<xs:pattern value="(([a-zA-Z0-9])*)([/])(([a-zA-Z0-9])*)"/>

I validated this pattern by XMLSpear

查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-04 02:02

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.

查看更多
登录 后发表回答