Results 1 to 8 of 8
Thread: Regex help needed
-
12-29-2012, 06:47 AM #1Aspiring Evangelist
- Join Date
- Jan 2007
- Location
- Kent, UK
- Posts
- 421
Regex help needed
Hi Guys,
We currently enforce some validation on our install for when a client sends an rDNS request into our system which is as follows:
$validate = "/^([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/";
I believe this forces something1.something2.something3
something1/2 can be anything where as something3 is limited to text and dots only (for the TLD) if I recall correctly.
The issue is, despite not being proper formatting, people often want to submit something.tld which our system currently blocks.
Can anyone suggest a correct syntex that will allow for:
something.tld
something.something.tld
something.something.something.tld
ETC?
ThanksRackSRV Communications Limited
UK Hosting specialists in Dedicated Servers & Server Colocation
Company: 06856870 VAT: GB 934 7073 15 Tel: 0330 229 1000
-
12-29-2012, 06:53 AM #2Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
You only want to support up to the fourth level? No support for IDNs?
-
12-29-2012, 07:01 AM #3Aspiring Evangelist
- Join Date
- Jan 2007
- Location
- Kent, UK
- Posts
- 421
The 'etc' part was meant to suggest that the examples I gave were exactly that. in essence I need to force something.tld or greater i.e. to prevent someone entering just 1 block of text or 2 blocks of text with the latter not matching the type of chars found in a tld (e.g. non letters or dots).
Does this make sense?RackSRV Communications Limited
UK Hosting specialists in Dedicated Servers & Server Colocation
Company: 06856870 VAT: GB 934 7073 15 Tel: 0330 229 1000
-
12-29-2012, 08:06 AM #4Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
Alright, so the number of sub domains shouldnt be limited, but the question is still whether you want to support IDNs. Alternatively you could of course convert them first and then run your check.
-
01-08-2013, 05:32 PM #5Junior Guru Wannabe
- Join Date
- Sep 2006
- Posts
- 37
Jon,
Change
$validate = "/^([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/";
(This seems overly complex/hacked on and hacked on. I'm surprised it (sorta) works)
to
$validate = "/^(\.[a-zA-Z0-9_-]+\.)+([a-zA-Z]{2,6})$/";
The first element (\.[a-zA-Z0-9_-]+\.) with match if there are + (meaning: one or more) of them. so "some_thing.some-thing." will match as well as "some5thing." and "1.two.3.four".
The second element ([a-zA-Z]{2,6})$ is your TLD and EOL. You said that part is working anyways?
My new version will validate "1.2.3.4.com" and "hi.net" and seems like it's what you want. I've checked it in bash and perl shell and should work for you.Gavin Rogers, full time problem solver.
-
01-08-2013, 06:00 PM #6Aspiring Evangelist
- Join Date
- Jan 2007
- Location
- Kent, UK
- Posts
- 421
Thanks Gavin, I've got it working now
RackSRV Communications Limited
UK Hosting specialists in Dedicated Servers & Server Colocation
Company: 06856870 VAT: GB 934 7073 15 Tel: 0330 229 1000
-
01-08-2013, 06:10 PM #7Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
I can only emphasise it (also for others who want to use it) again, keep in mind this does not cover IDNs.
Last edited by zoid; 01-08-2013 at 06:14 PM.
-
01-09-2013, 01:25 PM #8Web Hosting Master
- Join Date
- Nov 2006
- Location
- Karachi, Pakistan
- Posts
- 1,359
Technically a trailing dot is legal in a domain name. So example.com. is perfectly fine. But I don't think it will validate according to Gavin's regex. Maybe end it with a .?
Code:$validate = "/^(\.[a-zA-Z0-9_-]+\.)+([a-zA-Z]{2,6})\.?$/";
Similar Threads
-
(paid work) PHP regex guru is needed for very complicated regex requirement
By mrzippy in forum Employment / Job OffersReplies: 2Last Post: 03-30-2006, 05:10 PM -
Regex help needed please
By DoubleV in forum Programming DiscussionReplies: 1Last Post: 09-12-2004, 10:57 AM -
Regex help needed please!
By BigBison in forum Programming DiscussionReplies: 1Last Post: 09-03-2004, 04:25 PM -
domain matching regex needed.
By scott79 in forum Programming DiscussionReplies: 1Last Post: 06-03-2004, 08:57 AM -
REGEX How?
By hoster in forum Hosting Security and TechnologyReplies: 0Last Post: 09-10-2002, 07:33 PM