Reputation: 7855
I have this input text:
<div class="input text col-sm-6 col-xs-12 required">
<input name="data[Fornecedor][endereco]" placeholder="* Endereço" maxlength="255" type="text" id="FornecedorEndereco" required="required" autocomplete="off">
</div>
This address field have both letters and digits. How can I check with JQuery if it has a number apart from just text? (I want to display an error message informing the client of the necessity of including an address number)
Upvotes: 0
Views: 28
Reputation: 30607
Use a regular expression
$('#FornecedorEndereco').change(function() {
var hasDigit = /\d/.test($(this).val());
console.log(hasDigit);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="input text col-sm-6 col-xs-12 required">
<input name="data[Fornecedor][endereco]" placeholder="* Endereço" maxlength="255" type="text" id="FornecedorEndereco" required="required" autocomplete="off">
</div>
Upvotes: 1