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.
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
I tried this javascript, it's working fine.Thanks, @Rajat Agrawal
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)) {
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
Hi, @Neha Gupta try the below code.