XSD validation template to enforce LastName / FirstName

I need to force the LASTNAME / FIRSTNAME pattern Something like Smith / John.

Characters can be alphanumeric (lowercase or uppercase) and also include special characters such as "etc."


 <xsd:pattern value="[a-zA-Z0-9]/[a-zA-Z0-9]"/>


Basically the rules will be - Anything before the forward slash - Anything after the forward slash - Patterns like "/ John", "John /" should not be allowed

Thanks in advance.


source to share

2 answers


Assuming you don't need numbers in names:

        <xs:pattern value="[a-zA-Z]+/[a-zA-Z]+"/>


If you really want to accept numbers in names:

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


Remember, 0/0

for example, would be valid in this case.


        <xs:pattern value="\p{L}+/\p{L}+"/>


Explanation : \p{L}

Matches the Unicode code point in the Letter category.



Your limit should be like this ..

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


I have checked this XMLSpear template



All Articles