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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -