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 lettersi
modifier make them case insensitive
update:
- @oka correctly pointed out better add
^ $
indicate expression accept 1 character.
Comments
Post a Comment