26
Views
5
Comments
Solved
i want only text as a input in that field not any integer
Application Type
Reactive

Hello community i have a input field in a form i want only text as a input in that field not any integer and special character.

2020-07-21 19-28-50
Rajat Agrawal
Champion
Solution

Hi @Neha Gupta,

Apply below java script on OnReady Event of page or Block

function allowOnlyLetters(inputId) {

       const inputField = document.getElementById(inputId);

 if (!inputField) {

        console.error("Input field not found with ID:", inputId);

        return;

    }

        inputField.addEventListener('keypress', function(event) {

        const char = String.fromCharCode(event.keyCode || event.which);

                if (!/^[a-zA-Z\s]$/.test(char)) {

            event.preventDefault();         }

    });

}

allowOnlyLetters($parameters.InputId);


Hope this scripts helps you!!


Regards,

Rajat

2024-06-07 07-10-45
Leon Richard

I tried this javascript, it's working fine.
Thanks, @Rajat Agrawal 

2021-11-12 04-59-31
Manikandan Sambasivam

Hi,

Please try the code below

  $(document).ready(function () {

    $('.integerInput').on('keypress', function (e) {

      // Allow only digits (48-57) and prevent other characters

      var charCode = e.which ? e.which : e.keyCode;

      if (charCode < 48 || charCode > 57) {

        e.preventDefault();

      }

    });

    $('.integerInput').on('paste', function (e) {

      // Prevent pasting non-integer values

      var clipboardData = e.originalEvent.clipboardData || window.clipboardData;

      var pastedData = clipboardData.getData('Text');

      if (!/^\d+$/.test(pastedData)) {

        e.preventDefault();

      }

    });

  });


UserImage.jpg
Nani

Hi, @Neha Gupta 

There is one component called " Restrict Chars Reactive ", it will help you.

https://www.outsystems.com/forge/component-overview/8005/restrict-chars-reactive-o11


UserImage.jpg
Usha Rani

Hi, @Neha Gupta try the below code.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.