Link to home
Create AccountLog in
Avatar of kchall
kchallFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Validating a username input field - similar to coldfusion LEFT function

I have this:

function validateForm() {
      var valid = true;
      if (document.LoginForm.ContactNo.value.length == 0)      {
            alert("Please Enter a Username.");
            valid = false;
      }

Which checks if no user name has been entered (if true show alert box)

Also this:

      else if (document.LoginForm.ContactNo.value != "ADMN") {
            alert("Please enter an ADMN number.");
            valid = false;
      }
      else {
            return valid;
      }
}

Which checks if the entered consists exactly of the letters ADMN

However i need a case which checks if the first FOUR letters only of the entered text consists of the letters ADMN not that the whole string is just ADMN.

I believe in Coldfusion the syntax would be something like: Left(string, 4) EQ "ADMN".

I just cannot work out how to do this in Javascript.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account