Validating a username input field - similar to coldfusion LEFT function

Posted on 2006-03-22
Last Modified: 2013-12-16
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.

Question by:kchall
    1 Comment
    LVL 35

    Accepted Solution

    if(document.LoginForm.ContactNo.value.substring(0,4) == "ADMN")

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now