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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:49:56+00:00 2026-06-09T19:49:56+00:00

I am trying to make sure that a phone# is not all identical characters,

  • 0

I am trying to make sure that a phone# is not all identical characters, example 1111111111
The code I am using works but there has to be a cleaner way. I’ve tried loops but that only compares two consecutive characters at a time. This is what I am using now:

if (MainPhone.value != "")
            {               
                if ((MainPhone.value == 1111111111) || (MainPhone.value == 2222222222) || (MainPhone.value == 3333333333) || (MainPhone.value == 4444444444) || (MainPhone.value == 5555555555) || (MainPhone.value == 6666666666) || (MainPhone.value == 7777777777) || (MainPhone.value == 8888888888) || (MainPhone.value == 9999999999) || (MainPhone.value == 0000000000))
                {
                window.alert("Phone Number is Invalid");
                MainPhone.focus();
                return false;
                }
            }

I found this recommendation for someone else’ question but could not get it to work.

var dup = MainPhone.value.split('');
if all(dup == dup(1))
  • 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-09T19:49:58+00:00Added an answer on June 9, 2026 at 7:49 pm

    You can use a regular expression like this to check if all characters are the same:

    ^(.)\1*$
    

    Example:

    var phone = '11111111';
    
    if (/^(.)\1*$/.test(phone)) {
      alert('All the same.');
    }
    

    Demo: http://jsfiddle.net/Guffa/3V5en/


    Explanation of the regular expression:

    ^   = matches start of the string
    (.) = captures one character
    \1  = matches the first capture
    *   = zero or more times
    $   = matches end of the string
    

    So, it captures the first character, and matches the rest of the characters if they are the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to make sure that all my user will not logg in during
I am trying to download a CSV file using HttpResponse to make sure that
I have been trying to test my application to make sure that all the
I am trying to make sure that all of the translatable strings are present
I am trying to make a function that opens a window but makes sure
I am trying to make sure that uinput is running/loaded and that it works.
I am trying to make sure that user uses at least 6 characters as
Hi all I'm creating an invoice system and trying to make sure that the
I'm trying to make sure that my Managed to Unmanaged calls are optimized. Is
I am trying to create a validation that checks to make sure a domain/url

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.