javascript - JQuery if input starts with a value -
i managing check value inside postcode input field using following:
html:
<input type="text" class="cart-postcode2" size="10" tabindex="22">
jquery:
$('.cart-postcode2').keyup(function(){ var value = $(this).val(); if (value.indexof('bt') >= 0) { alert("is ireland"); } })
this working great want alert if starts bt , not contain bt in part of value, know if possible?
so typing bt2 9nh alert "ireland" typing ox2 8bt not
you can check if string starts bt
, indexof()
give index 0 if value stats bt
$('.cart-postcode2').keyup(function(){ var value = $(this).val(); if (value.indexof('bt') == 0) { alert("is ireland"); } })
Comments
Post a Comment