Jump to content

Phone number formatting and e-mail validation


Recommended Posts

You should add this code to the HTML block with Disabled HTML Editor just below search fields. Search field labels should contain Phone and Email parts of words. Example of the app provided below.

 

This soulition is perfectly fit for validating search fields on Search Report Data Page

 

<SCRIPT LANGUAGE="JavaScript">
    let validationForm = false;
    document.addEventListener('DataPageReady', function(event) {
        const searchInput= 'input[id^=Value]';
        document.querySelectorAll(searchInput).forEach(function (element, key, nodelist){
            const candidatePhone = "hone";
            const candidateEmail = 'mail';
            const searchLabelPath = nodelist[key].closest('tr').childNodes[0].childNodes[0].innerHTML;
            if(searchLabelPath.indexOf(candidatePhone)!=-1){
                        nodelist[key].maxLength = 14;
                        nodelist[key].placeholder='Type your Phone';
                        nodelist[key].onkeyup = function(keyUpEvent)
                        {
                            keyUpEvent = keyUpEvent || window.event;
                            const isCharacters=keyUpEvent.keyCode >= 65 && keyUpEvent.keyCode <= 90;
                            const isSpecial=keyUpEvent.keyCode >= 37 && keyUpEvent.keyCode <= 40;
                            if (isCharacters){
                                this.value = this.value.substr(0, this.value.length - 1);
                                return;    
                            }
                            const formattedValue = (this.value.replace(/[^\d]/g, ''));
                            switch(formattedValue.length){
                                case 7:
                                    this.value = (formattedValue.substring(0,3) + "-" + formattedValue.substring(3,7));
                                    break;
                                case 10:
                                    this.value = ("(" + formattedValue.substring(0,3) + ") " + formattedValue.substring(3,6) + "-" + formattedValue.substring(6,10));
                                    break;
                            }
                        }
            }

            if (searchLabelPath.indexOf(candidateEmail)!=-1){
                nodelist[key].maxLength = 25;
                nodelist[key].placeholder='Type your Email';
                document.addEventListener('BeforeFormSubmit', function(event) {
                    if(nodelist[key].value.indexOf('@')==-1){
                        event.preventDefault();
                        alert('Please check your Email adress.');
                     }
                });
            }
        })
       

    });
    

</SCRIPT>

 

phone_1_0_2019-Apr-12_0935.zip

Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...