javascript - How can I accept uppercase letters in my prompt? JS -


i know how accept uppercase b, o, , h newbase prompt. know .touppercase wondering add or if uppercase me in case. know can manually place capital letters in while test code. thanks, hope hear soon.

var integer = prompt("enter unsigned base 10 number:");        while (!(integer > 0 )){     var integer = prompt("enter unsigned base 10 number:");       }  var newbase = prompt("enter b binary, o octal, or h hexadecimal:");     while (!(newbase === "b" || newbase === "o" || newbase === "h")) {     var newbase = prompt("enter b binary, o octal, or h      hexadecimal:")     } alert("aye"); </script> 

how regex : /^[boh]$/i.test("b") //returns true both b or b , false other letter

for example: /^[boh]$/i.test(newbase)

  • [boh] accepted letters
  • i modifier make them case insensitive

update:

  • @oka correctly pointed out better add ^ $ indicate expression accept 1 character.

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -