solarisuser Posted June 21, 2007 Share Posted June 21, 2007 Hi All, Is it possible to combine these two regexs I use? I'm not well versed in regex.... First One: /^[a-zA-Z0-9 -]+$/ Second One: /^.{3,21}$/ Essentially, allow "a-zA-z0-9, spaces, and dashes", and it must be between 3 and 21 characters in length. Link to comment https://forums.phpfreaks.com/topic/56483-solved-can-i-combine-these-two-regexs-into-one/ Share on other sites More sharing options...
rea|and Posted June 21, 2007 Share Posted June 21, 2007 You could replace + with {3,21} /^[a-zA-Z0-9 -]{3,21}$/ or use a lookahead assertion like /^(?=.{3,21}$)[a-zA-Z0-9\x20-]+$/ In this case first it checks the number of chars and afterward it checks the characters. Link to comment https://forums.phpfreaks.com/topic/56483-solved-can-i-combine-these-two-regexs-into-one/#findComment-279137 Share on other sites More sharing options...
solarisuser Posted June 21, 2007 Author Share Posted June 21, 2007 thank you! Link to comment https://forums.phpfreaks.com/topic/56483-solved-can-i-combine-these-two-regexs-into-one/#findComment-279385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.