[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Validating a username input field - similar to coldfusion LEFT function

Posted on 2006-03-22
1
Medium Priority
?
333 Views
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.

Thanks.
0
Comment
Question by:kchall
1 Comment
 
LVL 35

Accepted Solution

by:
mrichmon earned 200 total points
ID: 16258827
if(document.LoginForm.ContactNo.value.substring(0,4) == "ADMN")
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 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