HTML5: Problem with not operator in pattern attribute of input text

4

I want to make the input text allow only the following strings:

site.com; site.com.br; site123.com123.br; site-123.com. But never: site-123-.com.br

My expression looks like this:

(([a-z0-9-]{3,})[^-])+\.([a-z0-9]{2,})(([.]{1})([a-z]{2}))?

That way, when I type: site.co*/@m.br, it is accepting.

That is, I want you to accept strokes, but never at the end of the first string or before the first dot.

    
asked by anonymous 10.10.2016 / 18:32

1 answer

1

Renan,

I've mounted this expression:

^[a-z0-9][a-z0-9-]{1,61}[a-z0-9](\.[a-z]{3,}(\.[a-z]{2})?)$

I did some tests, it solves the trace problem and validates several domain names. See if it meets your need.

    
28.10.2016 / 20:04