Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
Javascript regex url for domain or ip address

I am needing to check the url entered on a page and its still matching http:// only string. I want it to fail if user only enters http://

Regex pattern ^(https?:\/\/)(www\.)?(([a-zA-Z]+)?(\.[a-zA-z]{2,6})?)((\d{1,3}\.){3}(\d{1,3}){1})?$/gm

tests:

google.com  <---- fails as it should
https://google.com  <---- Pass
https:google.com  <---- fails as it should
www.cool.com.au  <---- fails as it should
https://asdsds.Com
http://a  <---- Pass
https://  <---- Pass **BUT SHOULD FAIL**
http://10.10.10.00  <---- Pass
http://www.cool.com  <---- Pass
https://123123.asd  <---- fails as it should
http://www.cool.com.au/ersdfs  <---- fails as it should
http://www.cool.com.au/ersdfs?dfd=dfgd@s=1  <---- fails as it should
http://www.cool.com:81/index.html  <---- fails as it should
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The main point here is to add (?!$) after ^(https?:\/\/), it will fail the match if there is end of string/line immediately after the protocol part.

You can use

^(?:https?:\/\/)(?!$)(?:www\.)?[a-zA-Z]*(?:\.[a-zA-Z]{2,6})?(?:(?:\d{1,3}\.){3}\d{1,3})?$

See the regex demo.

Note the {1} is redundant and need removing. [a-zA-z] (that does not match only letters) is most probably a typo, you must have meant [a-zA-Z].

I removed unnecessary capturing groups and converted capturing ones into non-capturing to get cleaner regex match structure, only use capturing mechnanism when you need to actually get the match parts.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda