В этом текстовое поле должно допускать только строки. Но без использования окна предупреждения, как проверить текстовое поле в jquery. Может ли кто-нибудь объяснить мне? И как проверить число в jquery.
$(function () {
$("#register-form").validate({
rules: {
Title: "required",
lan: "required",
Lati: "required"
},
messages: {
Title: "Please enter your Country name",
lan: "please enter longitude vale",
Lati: "Please enter lattitude value",
},
submitHandler: function (form) {
form.submit();
}
});
});
<form action="insert.php" method="post" id="register-form">
<table align="center">
<tr>
<td class="label">Title</td>
<td>
<input type="text" size="50" name="Title" id="Title" class="as_input" />
</td>
</tr>
<tr>
<td class="label">Lan</td>
<td>
<input type="text" size="50" name="lan" id="Lan" class="as_input" />
</td>
</tr>
<tr>
<td class="label">Lat</td>
<td>
<input type="text" size="50" name="Lati" id="Lati" class="as_input" />
</td>
</tr>
<tr>
<td></td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>
http://jsfiddle.net/Altynbek92/m1x3ko8g/
<input id="tt" type="button" value="click me!">
<input type="text" id="text1">
$('#tt').click(function() {
var tb1 = $("#text1");
if (isNullOrWhitespace(tb1.val())) {
tb1.tooltip({ items: tb1, content: "Displaying on click"});
tb1.tooltip("open");
} else {
tb1.tooltip( "option", { disabled: true } );
}
});
function isNullOrWhitespace(input) {
if (input == null) return true;
return input.replace(/\s/g, '').length < 1;
}
Один из способов сделать проверку на клавиатуре, размытие, образец ниже кода для числового и алфавитного,
JS FIDDLE SAMPLE
$('.numbersOnly').keyup(function () {
this.value = this.value.replace(/[^0-9\.]/g, '');
});
$('.numbersOnly').blur(function () {
this.value = this.value.replace(/[^0-9\.]/g, '');
});
$('.alphabetsOnly').keyup(function () {
this.value = this.value.replace(/[^a-zA-Z\ .]/g, '');
});
$('.alphabetsOnly').blur(function () {
this.value = this.value.replace(/[^a-zA-Z\ .]/g, '');
});
Вам просто нужно добавить этот класс в уважаемое текстовое поле.