How long can a TLD possibly be?

前端 未结 7 1920
忘了有多久
忘了有多久 2020-11-28 07:03

I\'m working on an email validation regex in PHP and I need to know how long the TLD could possibly be and still be valid. I did a few searches but couldn\'t find much infor

7条回答
  •  自闭症患者
    2020-11-28 07:43

    This is PHP code to get up-to-date vertical bar separated UTF-8 TLDs list to be used directly in a regular expression:

    
    

    To match a host name you could use it like this:

    $tlds=getTLDs('|');
    if (preg_match("{([\da-z\.-]+)\.($tlds)}u",$address)) {
      ..
    }
    

提交回复
热议问题