简体   繁体   中英

Regex for a 19 character string that includes special characters

I would like to create a regex that limits a string to 19 or 15 characters and also includes special character but out of order.

Examples are

847294729472903472c3c
 111 ( 3234) 3235
1234 + 1234

If a special character is any non-ascii letter or integer number, you can do the following:

new Regex("^((.{15})|(.{19}))$").IsMatch(text) && new Regex("[^a-zA-Z0-9]").IsMatch(text)

See on .NET fiddle: https://dotnetfiddle.net/vTyn7q

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