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


    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;
                        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);
                            const formattedValue = (this.value.replace(/[^\d]/g, ''));
                                case 7:
                                    this.value = (formattedValue.substring(0,3) + "-" + formattedValue.substring(3,7));
                                case 10:
                                    this.value = ("(" + formattedValue.substring(0,3) + ") " + formattedValue.substring(3,6) + "-" + formattedValue.substring(6,10));

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





Link to comment
Share on other sites

  • 2 years later...
  • 8 months later...

Hi All - In relation to Caspio's new feature of Worldwide SMS Notifications, if you would like your input phone number fields to be automatically formatted - you can use the International Telephone Input plugin. This JavaScript plugin is used for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder, and provides formatting/validation methods. To know more of the customization, you can check this link: https://github.com/jackocnr/intl-tel-input

Here's a sample result in DataPage:


After submission in table:


Related articles:


Hope it helps!

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

Just to add, if you also wish to validate value entered in an input field to make sure that it follows this format: www.websitename.com

Then you can use this code:


<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var inputField = document.querySelector('#InsertRecordNameofField');

  const value = inputField.value;
  const regex = /^www\.[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$/;

if (!regex.test(value)) {
alert('Invalid Submission!');

} else {




Make sure to replace "NameofField" with the actual name of the field that you want to validate before submitting.

Link to comment
Share on other sites

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.

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.

  • Create New...