简体   繁体   中英

Regular Expression to validate if user has provided the correct URI format or not

I am trying to write a regular expression or regex for my HTML input field with text type. The user should enter the URI in the input field. The URI would look something like this: urn:URNNamespace:**:class:ObjClassid .

Some of the examples of valid URI are as follows: urn:abc:testing:pqrs:1234556.1244 urn:wxyz:testing123:abc:1234556.* urn:global:standard:value:myvalue

I was trying to check only if the initial characters are URN using the expression ^(urn):// and check if the string contains the character : in it.

I just want to make sure that user enters valid URN similar to the one that's provided. Is there any better way I can use and achieve this?

I would recommend a really great tool called Regulex that helps you build regular expressions.

I tried to create the described pattern and ended up with:

^urn:\w+:\w+:\w+:\d+(\.\d+)?$

正则图

You can try and change it here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM