Skip to main content
Tidied title; trademark capitalization; acronym capitalization; spelling; grammar; layout.
Source Link
Tushar
  • 87.4k
  • 21
  • 164
  • 182

Javascript to change Change color of input text field not working

I'm not sure what iI could be doing wrong, but why when iI test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when iI apply the regexRegEx on the javascriptJavaScript it doesn'tdoesn't work properly? I mean, its only showing red for numeric or charscharacters. insteadInstead green for numeric and red for charscharacters. htmlHTML:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

javascriptJavaScript:

 function checkKey() {   var msisdn = document.getElementById("msisdn");     if (msisdn.value == /^[\d{9}]*$/) {    msisdn.style.color = "#00b300";   }  else {   msisdn.style.color = "#ff0000";   }  } 

Code on fiddler

Javascript to change color of input text field not working

I'm not sure what i could be doing wrong, but why when i test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when i apply the regex on the javascript it doesn't work properly? I mean, its only showing red for numeric or chars. instead green for numeric and red for chars. html:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

javascript:

 function checkKey() {   var msisdn = document.getElementById("msisdn");   if(msisdn.value == /^[\d{9}]*$/) {    msisdn.style.color = "#00b300";   }  else {   msisdn.style.color = "#ff0000";   }  } 

Code on fiddler

Change color of input text field not working

I'm not sure what I could be doing wrong, but why when I test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when I apply the RegEx on the JavaScript it doesn't work properly? I mean, its only showing red for numeric or characters. Instead green for numeric and red for characters. HTML:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

JavaScript:

function checkKey() { var msisdn = document.getElementById("msisdn");    if (msisdn.value == /^[\d{9}]*$/) { msisdn.style.color = "#00b300"; } else { msisdn.style.color = "#ff0000"; } } 

Code on fiddler

deleted 18 characters in body; edited tags
Source Link
Rohit Vipin Mathews
  • 11.8k
  • 15
  • 60
  • 113

I'm not sure what i could be doing wrong, but why when i test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when i apply the regex on the javascript it doesn't work properly? I mean, its only showing red for numeric or chars. instead green for numeric and red for chars. html:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

javascript:

 function checkKey() { var msisdn = document.getElementById("msisdn"); if(msisdn.value == /^[\d{9}]*$/) { msisdn.style.color = "#00b300"; } else { msisdn.style.color = "#ff0000"; } } 

Code on fiddler

Thanks in advance.

I'm not sure what i could be doing wrong, but why when i test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when i apply the regex on the javascript it doesn't work properly? I mean, its only showing red for numeric or chars. instead green for numeric and red for chars. html:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

javascript:

 function checkKey() { var msisdn = document.getElementById("msisdn"); if(msisdn.value == /^[\d{9}]*$/) { msisdn.style.color = "#00b300"; } else { msisdn.style.color = "#ff0000"; } } 

Code on fiddler

Thanks in advance.

I'm not sure what i could be doing wrong, but why when i test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when i apply the regex on the javascript it doesn't work properly? I mean, its only showing red for numeric or chars. instead green for numeric and red for chars. html:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

javascript:

 function checkKey() { var msisdn = document.getElementById("msisdn"); if(msisdn.value == /^[\d{9}]*$/) { msisdn.style.color = "#00b300"; } else { msisdn.style.color = "#ff0000"; } } 

Code on fiddler

Source Link
thclpr
  • 6k
  • 11
  • 58
  • 90

Javascript to change color of input text field not working

I'm not sure what i could be doing wrong, but why when i test the regular expression /^[\d{9}]*$/ on the website https://regex101.com/#javascript it match correctly if it's a number or not, but when i apply the regex on the javascript it doesn't work properly? I mean, its only showing red for numeric or chars. instead green for numeric and red for chars. html:

<input type="text" name="age" id="msisdn" onKeyUp="checkKey()"> 

javascript:

 function checkKey() { var msisdn = document.getElementById("msisdn"); if(msisdn.value == /^[\d{9}]*$/) { msisdn.style.color = "#00b300"; } else { msisdn.style.color = "#ff0000"; } } 

Code on fiddler

Thanks in advance.