jquery - Check if input starts with X, alert and clear if not -
showalert = false; $('input').keyup(function(){ var value = $(this).val(); if (value.indexof('+') == 0) { $(this).val(''); // clear input showalert=true; // alert user if (showalert==true) { console.log ("phone number must start +"); showalert = false; } } });
i want phone number input filed +
display alert once... code doesn't seem work.
please check link
you should match !="0"
this should jquery
var show=""; $('input').keyup(function(){ var value = $(this).val(); if (value.indexof('+') != 0) { $(this).val(''); if(show=="") { alert("phone number must start +"); } show="1"; } });
because want alert once
Comments
Post a Comment