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

click here

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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -