Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2007
    Location
    Kent, UK
    Posts
    421

    Exclamation 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?

    Thanks
    RackSRV Communications Limited
    UK Hosting specialists in Dedicated Servers & Server Colocation
    Company: 06856870 VAT: GB 934 7073 15 Tel: 0330 229 1000

  2. #2
    Join Date
    Aug 2001
    Posts
    5,597
    You only want to support up to the fourth level? No support for IDNs?

  3. #3
    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

  4. #4
    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.

  5. #5
    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.

  6. #6
    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

  7. #7
    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.

  8. #8
    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

  1. Replies: 2
    Last Post: 03-30-2006, 05:10 PM
  2. Regex help needed please
    By DoubleV in forum Programming Discussion
    Replies: 1
    Last Post: 09-12-2004, 10:57 AM
  3. Regex help needed please!
    By BigBison in forum Programming Discussion
    Replies: 1
    Last Post: 09-03-2004, 04:25 PM
  4. domain matching regex needed.
    By scott79 in forum Programming Discussion
    Replies: 1
    Last Post: 06-03-2004, 08:57 AM
  5. REGEX How?
    By hoster in forum Hosting Security and Technology
    Replies: 0
    Last Post: 09-10-2002, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •