Hello Regex-Pros!
I have tried to figure out how the validation of the house numbers work, but the conditional matching doesnt work for me...
I hope someone can help me out with my problem. I need to test the following input :
Valid :
4a-4b
Invalid:
4a-4a
My attempt :
^(\d+([a-z]{0,1}))-(\d+([^\2]))$
The problem is that the conditional pattern always matches.. The conditional pattern is incorrect, but I dont seem to find the bug.
I've been experimenting with the Regex-Coach, but no success.
Thanks in advance for the help.
Validation of House Numbers
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Validation of House Numbers
You can't use back references inside character classes. Use a negative look ahead instead:Preddy2008 wrote:Hello Regex-Pros!
I have tried to figure out how the validation of the house numbers work, but the conditional matching doesnt work for me...
I hope someone can help me out with my problem. I need to test the following input :
Valid :
4a-4b
Invalid:
4a-4a
My attempt :
^(\d+([a-z]{0,1}))-(\d+([^\2]))$
The problem is that the conditional pattern always matches.. The conditional pattern is incorrect, but I dont seem to find the bug.
I've been experimenting with the Regex-Coach, but no success.
Thanks in advance for the help.
Code: Select all
^\d+([a-z])-\d+(?!\1)[a-z]$Re: Validation of House Numbers
And if you want to validate more stuff like that (b precedes a), I suggest to analyze the matches $1 and $2 further in PHP.prometheuzz wrote:Note that this can match numbers like 123b-123a.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Validation of House Numbers
Indeed, regex is not the right tool to do all the work.GeertDD wrote:And if you want to validate more stuff like that (b precedes a), I suggest to analyze the matches $1 and $2 further in PHP.prometheuzz wrote:Note that this can match numbers like 123b-123a.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: Validation of House Numbers
I can't help but feel like validating addresses is fundamentally flawed to begin with. Especially international addresses. In England it's not uncommon for addresses to have no numbers at all, with the exception of a postal code. PO boxes are another fundamentally different format, and the list doesn't end there.
I usually collect an address in a single textarea and use the Google Maps API to try and parse it... I've had much better results that way than anything else I've ever tried.
I usually collect an address in a single textarea and use the Google Maps API to try and parse it... I've had much better results that way than anything else I've ever tried.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Validation of House Numbers
You could always send them confirmation mail similar to confirmation email, to ensure the address is correct. 
That won't annoy them at all.
'Congratulations! You have just signed up. You should be receiving a confirmation mail in order to activate your account within the next 168 hours. Make sure you tell your mailman to keep us out of your bulk mailbox.'
That won't annoy them at all.
'Congratulations! You have just signed up. You should be receiving a confirmation mail in order to activate your account within the next 168 hours. Make sure you tell your mailman to keep us out of your bulk mailbox.'
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: Validation of House Numbers
Why is this the BEST. IDEA. EVAR?????!!1!!!superdezign wrote:'Congratulations! You have just signed up. You should be receiving a confirmation mail in order to activate your account within the next 168 hours. Make sure you tell your mailman to keep us out of your bulk mailbox.'