Good morning,
I would like to have my input text accept only four numbers and dps of this "-" and accept only three numbers.
Is it possible with HTML and CSS only?
Good morning,
I would like to have my input text accept only four numbers and dps of this "-" and accept only three numbers.
Is it possible with HTML and CSS only?
Only with HTML and CSS I believe it would not be possible, but with jQuery it's easy to do that. Here's an example:
$(document).ready(function () {
var $campo = $("#cep");
$campo.mask('00000-000', {reverse: true});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scripttype="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.js"></script>CEP<inputtype="text" id="cep" name="cep" />
In this way the field will be limited only to numbers and the number of digits requested.
You can use the pattern
attribute together with required
:
<form>
<label for="CEP">CEP:
<input name="CEP" id="CEP" required pattern="\d{5}-\d{3}"/>
</label>
<input type="submit" value="Enviar" />
</form>
Remembering that the zip code (except for cheating) are% with% digit 5
and -
digits.
Fonte