简体   繁体   中英

Regex creation for JS validation

I'm having some trouble creating the proper regex to validate input. I feel it is pretty simple to do but am still having a couple issues.

the ideal input would be as follows without the quotes: "tests.xxxxxxx" with the x's being replaced with any alphanumeric character. the only non-alphanumeric character is the period that separates 'tests' from the second half of the string.

(tests\.){1}

You can use the following regex with test() to validate:

tests\.[a-zA-Z0-9]+

Edit: If you want to restrict only one tests you can use a lookahead:

tests\.(?!.*tests)[a-zA-Z0-9]+

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