Mohammad Faisal Mohammad Faisal - 5 months ago 46
Javascript Question

how to get input type email's value from jquery

I was trying to get the

<input type="email" name="mail">
's value from
jQuery
.

I've to run a validation for checking
mail
's value

<script>
function valid(){
var em = $.trim($('input:email[name=mail]').val());
if(em.length < 5){
alert('Please enter email id');
return false;
}
return true;
}
</script>


but the form is still submitting if the user left
mail
blank.

I've gone through jQuery API Doc but not found any
selector
for
email
. Why so?

Why it is not present there and how would I solve this problem?

Answer

you could do:

$.trim($("input[name='mail']").val());