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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:44:53+00:00 2026-05-20T09:44:53+00:00

I am creating my first plugin and decided to try and create a mask

  • 0

I am creating my first plugin and decided to try and create a mask plugin that would use the # character as the mask character. So if I called:

 ('input').mask('(###)-###-####');

The mask would become ( )- -

All #’s would be replaced by spaces so only the mask would show. I sort of skipped ahead of this and just wanted to see if as I get the keypress to work. What I wanted to do was as the user types a character, I want to put there character at the first occurrence of the # character. This is how I want it to be, the mask starts of as ( )- -. If the user types a 3, then it should display
(3 )- -. Next, it might be something like (35 )- -. This goes on until the mask is complete. The below scripts is not very good and is probably not the best way to go at it, but just remember I am just trying to learn.

(function($) {
$.fn.mask = function(options) {

var
    defaults = {
        mask: '',
        maskColor: '#c4c4c4',
        inputColor: '#000000'
    },
    settings = $.extend({},defaults,options);

    this.keypress(function(e)
    {
        var text = '';
        var length = settings.mask.length;

        for(var i = 0; i < length; i++)
        {
            var c = settings.mask.charCodeAt(i);

            if(c != '35') //35 is the # character
            {

                text += settings.mask.charAt(i); /*Trying to do (342)-292-2029  
                                                 for example, but after the  
                                                 first character, it does 
                                                 ()-()-()3 instead. */
            }
        }
        $(this).val(text);
    });
}
})(jQuery);   
  • 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-20T09:44:54+00:00Added an answer on May 20, 2026 at 9:44 am

    I played around with this a little bit here http://jsfiddle.net/gJ68n/ This could certainly be optimized, but I think it might get you moving in the right direction.

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

Sidebar

Related Questions

I'm creating a small jQuery plugin for my CMS that styles certain form input
I am creating my first plugin and have a single function that controls the
I'm working on creating my first plugin for rails. I'm still pretty new to
I am creating my first wordpress plugin. one of the questions i have is
I'm trying to create a hook in one Wordpress plugin that could be used
We all may know the following snippet that gets the first entry of the
I'm creating a plugin/bookmarklet that will take an XML document embedded within the <textarea>
My ultimate goal is to create an eclipse plugin that sets up a PDT
I'm interested in creating a plugin for use on my LiveView™ but I am
I'm creating a jquery plugin for sorting and pagination a table (I know that

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.