On my webpage I have a form where a user enters information for their article. Right now I use jQuery to check if the entered values are not empty, if they are I show an error message.
Current validation
//Story Form
$('.error').hide(); //Hide error message initially
$(".button").click(function() { //On button click
$('.error').hide();
var title = $("input#sc_title").val();
if (title == "") { //if title is empty
$("label#title_error").show(); //show error
$("input#sc_title").focus(); //focus on title field
return false;
}
});
Right now it only checks if title == "". How would I edit the code to also check if there are at least 10 characters entered e.g. if title is empty and less than 10 chars are entered, show an error?
if user puts 20 space character in the title field in that case title.length returns 20 and it satisfy true condition so you can use jquery trim also