Js masks for phones. We mask and check the phone field using jQuery. Immediately need a mask

Golovna / Zakhist

At first glance, the answer is obvious: enter the telephone number field as a backup requirement. There are also some places where users can sign from the site through the application fields. For example, programs, software, websites for selling content. However, customer numbers for such projects are important as additional information that allows for the possibility of interaction with potential clients in the future. Moreover, it is clear that the simplest and most effective solution is the use of a mask. Let's bring it up with cases.

Why is the mask required?

The input mask shows which format requires entering data in the field. For example, if you enter a telephone number without a location code or a telephone number in the address field, you will not be able to navigate to the desired location. The form mask will provide a one-to-one view of the data, making it easier to search and manage the database. According to Netpeak recommendations, the mask for entering a telephone number is a mandatory element of the order form on the site. However, the practical recommendation of our managers is based on successful client cases.

Since the site specialized in programs, the field for entering a number on the site was required. To make the change possible, a hundred clients who filled in the “phone” field in the order form on the site, we signed up to change the account in Google Analytics. The “telephone” field has not filled in the login from nine buyers. Birches were given away the mask, and the women began to wear them. For the purity of the experiment, the field was stripped of the necessary rubber for filling and no other changes were made.
The result for Berezen is 19 numbers with 22 backers who filled out the application. In other words, 85% of clients who lost the program lost their phone number.

Case for the information center website: increased filling in the telephone number field by 15.4%

The client’s website provides services for writing essays, coursework, dissertations and other works. The telephone number of the correspondent is necessary for contacting, but on the site this field was not required. Koristuvach may not remember the form or write anything in this field. As before, at the first stage we installed an option to fill out the “phone” field in Google Analytics. Among the list of 59 applications blocked by the site, 15 did not have numbers. Thus, the company rejected only 74.6% of submitted forms with a registration number. Then we added a mask to enter into the phone field. The website received 60 applications. In case of this, 6 completed forms were not included in the client’s phone number. Also, 90% of submitted payment forms filled in the phone field correctly. Over the month - an increase of 15.4% after entering the number mask. Nasamkinets is an internal case of the agency.

The number field in the order form on the Netpeak website is also required. All telephone numbers are important so that clients always know the number and status of their application (we rely on SMS data), as well as to optimize the work of account managers. The period of the experiment, as in the advanced butts, is two months. Through the war, masks for entering numbers appeared, filling out hundreds of forms from 44% to 83% - by 39.4%.
After the experiment, we sent the mask to the website. The field for entering the number is no longer required. The application will not be processed if the wrong number is entered in the field. In this case, the first digits in the mass change in position on the edge, where they are located on the website. If we are talking about the form of advance payment, then it is important to know how clear the application with telephone numbers is. We took all the applications that were received through the application form and counted the hundreds that were converted into clients without a number or number with it. The remaining ones showed the greatest increase by 0.81%.

Note: just because a person gives you their number from the form, there is no guarantee that the funds will be reinstated.

As we speak about the form of forward engagement, the possibilities of reactivating clients come to the fore, the possibilities that open up to marketers who have created a database of special phone numbers of clients. We will learn about successful cases of reactivation in one of our new posts. In the meantime, let’s read about what you can do before any actions with telephone numbers in the database. Share in the comments your satisfaction with the implementation of the entry mask for phone numbers and your concerns about the number of applications that have arrived.

This jQuery plugin allows you to automatically select a matching input mask based on the phone number entered. This allows you to create a phone number on the side of the website for those who have seen and bezpomilkovym. In addition, subdivisions of the plugin may be different in other areas, since entry rules can be presented in the form of several entry masks.

Entry On websites, it is necessary to enter information about the telephone number. It so happened that each country has the right to establish its own rules for dialing and double numbers, as a result of which a confusion periodically arises between residents of different countries: some called the number with the leading digit 8, others - from the wire One number is 0, and the third is the + sign. The main solution In order to reduce the complexity of the problem and bring the numbers to a single format, there are 3 main solutions:
  • You are prompted to enter the number using the additional entry mask. Advantage: display the number to the minimum possible in the number. Nedolyk: the skin edge has its own writing for the day of the number.
  • Koristuvachev is asked to directly select a region and directly enter the part of the number that is missing; Possibly due to the mask being frozen in place. Advantage: the possibility of using different masks for different regions (as well as regions in the middle of the region). Shortcomings: the list of edges (and regions in the middle of the skin edge) may be larger; The phone number ceases to be displayed as a whole (or reprocessing is required before saving and displaying the number).
  • Place a + sign in front of the number (behind the input spaces) to allow you to skip entering numbers. Advantages: ease of implementation. Not enough: availability of number display.
  • Proposed solution As a result, it was decided to modify the original input mask so that it was changed according to the line value of the number. In addition, when you enter a number, it will display the name of the country that was entered. This approach, subjectively, can solve all the shortcomings of the treatment.

    Based on the fact that the number of countries in the world is remarkably small, it was decided to compile a list of masks for all countries. As a matter of fact, news reports published on the website of the International Electric Telecommunications Union were widely reviewed.

    Collecting this information yielded many surprises. In the process of collecting information, it was necessary to include all possible options for telephone numbers, in the region. However, due to the large amount of manually collected information, it is possible that inaccuracies have become present in the collected database. In an hour it is planned to make corrections to the cob set.

    Software implementation The core of the input mask is the vicoristan implementation of jquery.inputmask, which Habrahabr has discussed a lot about. This plugin is currently being actively developed and is being designed in such a way that it’s easy to just write an extension. However, this task of writing such an expansion turned out to be practically impossible. I began to improve and rewrite the output plugin to suit my needs, because... Since the author continues to actively work on expanded functionality, the result of the stagnation of my edits may be problematic. Therefore, I had the opportunity to write a plugin over the main core that handles (and overrides) external activities and performs data modification. In order to transfer your binders of new inputs to the pickers of the main plugin, use the jquery.bind-first plugin-library. When developing the rules of sorting, the following mentalities were adopted:
  • All symbols in the input field are divided into 2 types: significant symbols (my selection has the # symbol, which means a significant number, numbers 0-9) and decorative symbols (all others).
  • Another type of symbols in the input mask is template symbols (in some cases the # symbol) and others.
  • As a result, the following sorting rules emerged in the order of their classification:

  • When changing 2 masks character by character, only significant characters (not decorators) are accepted.
  • Various wildcard characters are treated as equals, and other significant characters are equal to their code.
  • Non-template characters are always smaller than template ones and as a result are more varied.
  • The shorter the number of significant symbols in the input mask, the greater the value of the input mask.
  • Search for the skin mask input When the input text with the black mask is equalized, the least significant characters of the skin mask are taken from the sorted list. If the row appears to follow the input mask, regardless of the fact that all the leading characters have been verified, the given input mask is considered inconsistent. If the input text is satisfied with a number of input masks, then the first one of them is rotated. Then, in the found pattern, all significant symbols (including non-template ones) are replaced by a template one, which is a combination of all the symbols allowed by any of the template symbols.
    • keydown - followed by pressing the Backspace and Delete keys - by changing the flow mask entered before, as the main processor removes one character from the text. In addition, you must press the Insert key, which changes the text input mode for synchronization.
    • keypress - fragments of the character to be entered may not be allowed by the original input mask (all significant characters in it are replaced with template ones), you need to check the new row to match one of the allowed masks. If there are no such masks, then the input to the symbol is discarded, otherwise the input mask is updated, after which the input is transferred to the kernel analyzer.
    • paste, input - paste text from the clipboard. Before transferring the processing to the kernel, a mask is selected for the row that resulted from pasting the text from the clipboard. Once the input mask has not been selected, the text is trimmed character by character from the end until the text is satisfied with one input mask. A similar operation is carried out when the text in the input field is corrected by clicking the val() function, as well as when the input mask is initialized, since it is set to the input field.
    • dragdrop, drop - the process is similar to paste.
    • blur - additional processing for the purpose, since the mode of clearing the text when losing focus is increased, since it does not satisfy the input mask. This idea is transferred after the main compiler, to the top of the front ones.

    All ideas are displayed within the scope of the entered mask. This allows you to avoid incorrect behavior when clicking on the inputmask after initialization of the input (since the kernel, when initializing, remembers all previously installed probes in the inputmask space).

    Example wiki Format of the list of masks The list of masks is a JavaScript array of objects, important with a different set of powers. At least one power, which is to place the input mask, may be present in all objects in the array. The name of the parameter to apply the mask may be sufficient. Below is a fragment of such an array:
    [ … ( "mask": "+7(###)###-##-##", "cc": "RU", "name_en": "Russia", "desc_en": "", " name_ua": "Russia", "desc_ua": "" ), ( "mask": "+250(###)###-###", "cc": "RW", "name_en": " Rwanda", "desc_en": "", "name_ru": "Rwanda", "desc_ru": "" ), ( "mask": "+966-5-####-####", "cc ": "SA", "name_en": "Saudi Arabia", "desc_en": "mobile", "name_ru": "Saudi Arabia", "desc_ru": "mobile" ), ( "mask": "+966- #-###-####", "cc": "SA", "name_en": "Saudi Arabia", "desc_en": "", "name_ru": "Saudi Arabia", "desc_ru": " " ), … ] Plugin connection parameters Before connecting, you need to select and sort the list of masks. It is important to avoid the offensive functions of the Vikons:
    $.masksSort = function(maskList, defs, match, key)
    • maskList - an array of objects that save input masks (a fragment of a marvelous object);
    • defs – an array of template symbols (in my case, this is the # symbol);
    • match - a regular expression that describes significant characters (in this case /|#/);
    • key – name of the object parameter to the array to place the input mask.

    When connected, the plugin is passed a special object that describes its robot. This object contains the following set of parameters:

    • inputmask - an object that contains parameters that are passed to the main inputmask plugin;
    • match - a regular expression that describes meaningful characters, in addition to template ones;
    • replace - a wildcard character that replaces all significant characters; may be in the object of the designated object in putmask;
    • list – array of objects to describe input masks;
    • listKey – the name of the parameter in the middle of the object that saves the input mask;
    • onMaskChange - a function that is called when the input mask is updated; As the first parameter is passed to an object in an array, the input mask of each one matches the entered text, and the other - the accuracy of the assigned mask: true - the input mask matches the input mask, false - for a reliable value of the mask, additional characters must be entered.

    To initialize the plugin, you must place the input mask method before the input field:
    $.fn.inputmasks = function(maskOpts, mode)

    • maskOpts - an object that describes the work of the plugin;
    • mode – non-language; At the moment, the value isCompleted is supported - as a result, the method turns true if the text in the input field is added and false in the other case.
    Example of plugin connection
    Input mask var maskList = $.masksSort($.masksLoad("phone-codes.json"), ["#"], /|#/, "mask"); var maskOpts = ( inputmask: ( definitions: ( "#": ( validator: "", cardinality: 1 ) ), //clearIncomplete: true, showMaskOnHover: false, autoUnmask: true ), match://, replace: "# ", list: maskList, listKey: "mask", onMaskChange: function(maskObj, completed) ( if (completed) ( var hint = maskObj.name_ru; if (maskObj.desc_ru && maskObj.desc_ru != "") ( hint + = "(" + maskObj.desc_uk + ")"; ) $("#descr").html(hint); ) else ( $("#descr").html("Input mask"); ) $(this ).attr("placeholder", $(this).inputmask("getemptymask")); ) ); $("#phone_mask").change(function() ( if ($("#phone_mask").is(":checked")) ( $("#customer_phone").inputmasks(maskOpts); ) else ( $ ("#customer_phone").inputmask("+[###################]], maskOpts.inputmask) .attr("placeholder", $("# customer_phone ").inputmask("getemptymask")); $("#descr").html("Input mask"); ) )); $("#phone_mask").change(); Demonstration An example of a demo of the expanded view plugin

    © 2024 androidas.ru - All about Android