Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
   Compare ISP   Rate your ISP
   Glossary   Glossary
Please login or register.

Login with username, password and session length
Advanced search  


Author Topic: javascript regex  (Read 1187 times)


  • Reg Member
  • ***
  • Posts: 951
javascript regex
« on: March 02, 2018, 11:02:44 AM »

anyone any good at javascript regex?

i'm trying to add validation on an html form field, all is fine except for one particular field.
this field only requires a value when the preceeding form field is answered as "YES", and when it is required it can only be numbers (0-9).

at the moment i have it split across two checks - which obviously isn't ideal.
the first check works but the second check is kicking in even when the answers is "NO" on the preceeding field.

Code: [Select]
if ((x7 == "YES") && (x7b == null || x7b == "")) {
    alert("Heat Control Estimated LTS must be entered");
    return false;
if ( (x7 == "YES") && (/^[0-9]+$/.test(x7b)) ){
} else {
    alert("Invalid Heat Control Estimated LTS; must only be numbers");
    return false;

so 1) can i combine the check into one? and 2) why is the second check not working as expected?