XSD Validation Pattern to Enforce LastName/FirstName

纵然是瞬间 提交于 2019-12-10 21:06:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!