fael097 Posted June 23, 2010 Share Posted June 23, 2010 hi, i need a pregmatch that validades a string from a field with numbers, letters, and spaces only. maybe i could use dashes, commas and accented letters later, but i dont know anything about regex, and its kinda hard to learn it with the available tutorials, so i'd be happy to have just my first need. someone can help? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/ Share on other sites More sharing options...
cags Posted June 23, 2010 Share Posted June 23, 2010 #^[a-z0-9 ]+$#i Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1076248 Share on other sites More sharing options...
salathe Posted June 24, 2010 Share Posted June 24, 2010 i dont know anything about regex, and its kinda hard to learn it with the available tutorials What about the "available tutorials" makes it hard to learn? Where have you looked so far? There is a lot of very good information out there from explaining the absolute basics of regular expressions to ultra-in-depth discussions. Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1076496 Share on other sites More sharing options...
fael097 Posted June 25, 2010 Author Share Posted June 25, 2010 thanks cags! works like a charm. @ salathe: what makes it hard to learn (well, hard to master) is the extensive reading. i'll probably only use regex with pregmatch ever Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1077117 Share on other sites More sharing options...
ZachMEdwards Posted June 27, 2010 Share Posted June 27, 2010 An alternative pattern: $pattern = '/[\w ]/'; Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1077904 Share on other sites More sharing options...
salathe Posted June 27, 2010 Share Posted June 27, 2010 Zach, how on earth is that comparable to what fael097 wants? fael097, I can't do anything about the "extensive reading" (it's not really a lot... or if it is, you're probably re-reading the same thing over and over or not covering just the basics). Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1077941 Share on other sites More sharing options...
ZachMEdwards Posted June 28, 2010 Share Posted June 28, 2010 It's the same thing as yours except mine has uses the shorthand \w ([a-zA-Z0-9]) Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1078057 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 It's the same thing as yours except mine has uses the shorthand \w ([a-zA-Z0-9]) Salathe hasn't posted a Regex in this thread, so it's not the same as his. Assuming you meant my pattern, it's still nowhere near the same. The OP wanted a pattern that would mean the string only contained those characters, which your pattern doesn't enforce at all, it merely checks there is at least one of them present. It also matches more characters since it will match underscore by default, and depending on the locale settings on the server potentially things such as accented characters. Quote Link to comment https://forums.phpfreaks.com/topic/205666-validate-input-string-with-letters-numbers-and-spaces/#findComment-1078067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.