Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:26:52+00:00 2026-05-27T00:26:52+00:00

I have created a JavaScript function for validation of US Driving License. Issue is

  • 0

I have created a JavaScript function for validation of US Driving License. Issue is function is browser dependent. That is function creates error in IE but run fine in MOZILLA AND CHROME..

I have validated it as first three digit should be either 0 or 1 or 2 or 3.

    //license number
    var strFilter = /^[0-9]*$/;
    var chkVal36 = document.getElementById("license").value;
    var chkVal37 = document.getElementById("license").value.length;
    var chkVal38 = document.getElementById("license").value;

    if ((!strFilter.test(chkVal36)) || ((chkVal36 !== "") && (chkVal36 === 0)) || (chkVal36 !== "") || (chkVal37 !== 8) || ((chkVal38[0] !== 0) && (chkVal38[0] !== 1) && (chkVal38[0] !== 2) && (chkVal38[0] !== 3))) {
        alert("Please enter valid 8-digit license number\r\n(Only digits)");
        document.getElementById("license").focus();
        document.getElementById("license").style.background = "#DFE32D";
        document.getElementById("license").value = null;
        return false;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:26:53+00:00Added an answer on May 27, 2026 at 12:26 am

    You can’t do string array indexing like chkVal38[0] in older versions of IE.

    I would suggest this cleaned up and simplified code:

    //license number
    var strFilter = /^[0-3][0-9]{7}$/;
    var obj = document.getElementById("license");
    
    if (!strFilter.test(obj.value)) {
        alert("Please enter valid 8-digit license number\r\n(Only digits)");
        obj.focus();
        obj.style.background = "#DFE32D";
        obj.value = "";
        return false;
    }
    

    Working example here: http://jsfiddle.net/jfriend00/ZUajd/

    Changes:

    • Moved all the validation into the single regex (leading 0-3, all numbers and 8 total chars).
    • Retrieved the DOM object once and then use that reference rather than retrieving it every time
    • Clear the field by setting to “”, not null.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
Ok, I have one JavaScript that creates rows in a table like this: function
I have created new rows using Javascript function addRow(id) , but I can't delete
I've created a javascript function that allows me to validate if one field or
I have a JavaScript function named openDatabase() that starts with: function openDatabase() { try
I have created a function using reg-ex to validate a field in JavaScript. My
I have created windows phone gap application. In that it internally uses browser called
I created an index.html page that have 3 different tabs. With the function tabs()
First i have declare that i am new to javascript. I have created a
I have created two JavaScript files. One file is "validators.js" and the other is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.