ram4nd Posted September 30, 2009 Share Posted September 30, 2009 How can I do a pattern that matches if there is A-Z, a-z, -, space Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/ Share on other sites More sharing options...
thebadbad Posted September 30, 2009 Share Posted September 30, 2009 Need more info. Are those chars the only allowed, or do you just want to check if one of them are found in the string? Must the string have a minimum and/or maximum length? Can it consist of e.g. spaces only? Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/#findComment-927575 Share on other sites More sharing options...
ram4nd Posted September 30, 2009 Author Share Posted September 30, 2009 actually i want to control the name field from form Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/#findComment-927577 Share on other sites More sharing options...
thebadbad Posted September 30, 2009 Share Posted September 30, 2009 Did you totally overlook my questions?? Guessing: <?php if (preg_match('~^[a-z -]+$~iD', $str)) { //the string contains only a-z, A-Z, hyphens and/or spaces, and is at least one char long } else { //the opposite } ?> Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/#findComment-927581 Share on other sites More sharing options...
ram4nd Posted September 30, 2009 Author Share Posted September 30, 2009 how can you make it at least 2 characters long, would be awesome if you could explain the pattern, but not necessary Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/#findComment-927598 Share on other sites More sharing options...
thebadbad Posted September 30, 2009 Share Posted September 30, 2009 <?php if (preg_match('~^[a-z -]{2,}$~iD', $str)) { //the string contains only a-z, A-Z, hyphens and/or spaces, and is at least two chars long } else { //the opposite } ?> Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/#findComment-927602 Share on other sites More sharing options...
ram4nd Posted September 30, 2009 Author Share Posted September 30, 2009 thank you very much, is pattern much longer if only the first letter of sentence can be big. No the first char, but first letters of sentences. If it will be longer like double or so then you don't have to waste your time. Link to comment https://forums.phpfreaks.com/topic/176040-preg_match/#findComment-927603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.