javascript - Make user input start with either "BR" or "BT" -


i have input field , check if input entered starts either "br" or "bt". example br1234 valid jh1234 not valid. @ moment can check "br" , not "bt".

this code have far:

 if (id.indexof('br') === 0) || (id.indexof('bt') === 0){ } else { id = "invalid id" document.getelementbyid('id').innerhtml = id return false; 

check have proper parentheses in right positions. condition if statement contains id.indexof('br') === 0 because closed parenthesis it.

if (id.indexof('br') === 0 || id.indexof('bt') === 0) {     // ... } 

you can use string.prototype.startswith check if string starts desired string.

if (id.startswith('br') || id.startswith('bt')) {     // ... } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -