Can someone help me please, I want to show an error when the user makes an invalid input with jquery.
It works if the input is null, but does not work with RegEx.
Here is the html code :
<div class="error" style="padding:5px 10px;background-color:yellow;border:1px solid red;border-radius:5px;display:none"></div>
<input type="text" name="nama">
<input type="submit" name="submit" value="Cek">
And here the jQuery
$(document).ready(function () {
var justChar = /^[a-zA-Z]+$/;
$('input[name="submit"]').click(function () {
if ($('input[name="nama"]').val() === "") {
$('.error').html('<ol></ol>');
if ($('input[name="nama"]').val() === "") {
$('.error ol').append("<li>Name Must Be Require</li>");
} else if (!justChar.test($('input[name="nama"]').val())) {
$('.error ol').append("<li>Name Must Be Character</li>");
}
$('.error').slideDown('slow');
return false;
}
return true;
});
});
i've write in jsfiddle
if ($('input[name="nama"]').val() === "") {