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 8652463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:18:48+00:00 2026-06-12T14:18:48+00:00

I am trying to write javascript code for making sure a field in my

  • 0

I am trying to write javascript code for making sure a field in my form has its first 2 characters as alphabets (US) and the rest 8 are numerics.

The total has to be 10, and if any of these are not satisfied, I should throw up an alert box.

I am checking for numerics now but I don’t know how to combine checking for alphabets and numerics in the same field.

Here is my code for checking for numerics.

Please help me out! sid is my field name.

// only allow numbers to be entered
var checkOK = "0123456789";
var checkStr = document.forms[0].sid.value;
var allValid = true;
var allNum = "";

for (i = 0; i < checkStr.length; i++)
{
    ch = checkStr.charAt(i);
    for (j = 0; j < checkOK.length; j++)
        if (ch == checkOK.charAt(j))
            break;

    if (j == checkOK.length)
    {
        allValid = false;
        break;
        if (ch != ",")
            allNum += ch;
    }
    if (!allValid)
    {
        alert("Please enter only 8 numeric characters in the \"sid\" field.");
        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-06-12T14:18:49+00:00Added an answer on June 12, 2026 at 2:18 pm

    A single regular expression will easily perform this check :

       /^[a-zA-Z]{2}\d{8}$/
    

    /^ match beginning of string

    [a-zA-Z]{2} match exactly 2 alphabetic characters

    \d{8} match exactly 8 digits

    $/ match end of string

    Use as follows :

     /^[a-zA-Z]{2}\d{8}$/.test (str)   // Returns true or false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write code of timer countdown with javascript, sql , c# ,
I cannot write Javascript code yet, and I'm trying to edit some code that
I am trying to write a javascript code that would change the value of
Alright... I'm trying to write some javascript code that will apply to an html
I'm trying to write a small javascript code to query data filtered by date.
I'm trying to write a Javascript Zip Code lookup utility. 1) The User will
I'm sure I'm going to have to write supporting javascript code to do this.
I am trying to write a greasemonkey javascript code for specifically my own page.
Trying to write a javascript bookmarklet to jump from a front end link into
I'm trying to write a javascript function that adds some DOM nodes to the

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.