| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 60179 | 2005-07-25 05:03:00 | php string validation check [A-z0-9_-] | Morgenmuffel (187) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 375125 | 2005-07-25 05:03:00 | Hey all, I am trying to write afunction to test that a username is valid and only contains alphanumeric characters and the underscore character as below <?php function isUsername($element) { return !preg_match ("/[A-z0-9_-]/", $element); } ?> But When i try entering a username like say 'nigel' (sans quotes of course) it returns a fail any suggestions would be much appreciated |
Morgenmuffel (187) | ||
| 375126 | 2005-07-25 05:17:00 | Try: <?php function isUsername($element) { return !preg_match ("/[a-zA-Z0-9_\-]/", $element); } ?> |
vinref (6194) | ||
| 375127 | 2005-07-25 05:33:00 | nz.php.net | mejobloggs (264) | ||
| 375128 | 2005-07-25 06:32:00 | well i am now officially lost, for some reason vin refs suggestion doesn't work <?php function isUsername($element) { return !preg_match ("/[a-zA-Z0-9_\-]/", $element); } ?> it makes sense, but I can't get it work thanks for the other link mejoebloggs, I'll read through that to see if I can make a function that works so I understand it must be a record for me edit: 3 <?php function isUsername($element) { return !preg_match ("/[^A-z0-9_\-]/", $element); } ?> seems to work Thanks all If it fails I'll be back |
Morgenmuffel (187) | ||
| 1 | |||||