Jump to content
frobber

StringRegExp - validate domain tld & cctld

Recommended Posts

Hi everyone.

first of all thank you for all the good forum post - they helped me a lot to start digging into Autoit.

But I am at a point know where I am lost and still can't find the right way to use StringRegExp in my script.

 

How can I validate if a string is a valid tld or cctld (example: domain.com or domain.co.uk

 

1. Element (the name before the dot) has to be only Letters, Number or the minus sign:   [A-Z0-9-]+

2. Element has to be 1 dot:  \.

3. Element the tld can only be letters: [A-Z]+

...that would be for  TLD
 

4. + 5.  Element the cctld  is optional but max once and has to be  "dot followed by only letters" : \.[A-Z]?

 

My best string result so far is:

StringRegExp($domains[$i], "(?i)([A-Z0-9-]+\.[A-Z]{2,10}){1}$")

 

But this see domain.co1.uk as valid which is wrong because  only letters are allowed after the dot

 

Can anyone help me here?

Thanks

Uwe

Share this post


Link to post
Share on other sites
Posted (edited)

Hi @frobber, and welcome to the AutoIt forums :welcome:
Maybe something like this?

(?i)^([-a-z0-9]+\.[a-z]+(?:\.[a-z]+)?)$

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Wow - works amazing!

I will get a cup of coffee now and investigate what you have changed.

Thanks

Share this post


Link to post
Share on other sites

@frobber
Happy to have helped and, you're welcome :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...