| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 125084 | 2012-06-05 22:59:00 | Writing Regular Expressions | Jstewart (16241) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1279826 | 2012-06-05 22:59:00 | Hi there - I'm currently trying to write some regular expressions for some software we are using and wondering if someone can let me know if I have done the two I need correctly: One expression is for a username and I have: "^([a-zA-Z0-9 ]){3,20}$" This is only meant to allow any letter (lower case or capital), any number between 0-9 and a space and must be between 3 and 20 characters. For the password I have: "(?!^[@]*$)(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9@]{8,63})$" This is only meant to allow @,0-9,a-z and A-Z. This must be between 8 and 63 characters. Thank in advance! James |
Jstewart (16241) | ||
| 1279827 | 2012-06-05 23:17:00 | It would help to know what language you are using. The first part of the first one will need something to separate them. | mikebartnz (21) | ||
| 1279828 | 2012-06-05 23:46:00 | Depending on the language used, the first one looks correct. I would've expected the second to simply be "^[a-zA-Z0-9@]){8,63}$" - again, depending on the language. | inphinity (7274) | ||
| 1279829 | 2012-06-05 23:48:00 | To be honest, I have no idea what language this is in. It's just a regular expression that uses the rules to allow users to enter a username and password into our CRM software. The original codes were: Const USERNAMEPATTERN = "^([a-zA-Z0-9]){3,20}$" Const ASSWORDPATTERN = "(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,63})$" These codes work perfectly at the moment but I am needing to relax the rules they use slightly to allow spaces in the username and @ in the password, so I changed the code to: Const USERNAMEPATTERN = "^([a-zA-Z0-9 ]){3,20}$" Const PASSWORDPATTERN = "(?!^[@]*$)(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9@]{8,63})$" Regards James |
Jstewart (16241) | ||
| 1279830 | 2012-06-21 10:36:00 | Infinities second RegEx looks sound to me too, your second looks to be a bit more complex than I think you are describing? | adslgeek (14687) | ||
| 1 | |||||