1071
Views
4
Comments
How to use regex to validate only alphabets
Question

Hi Team,

I have a Input block with input type as Text. I want to apply regex to filter out numeric numbers and Special characters on keypress  for Mobile Development.(eg., Name inputfield must take only Alphabets)

I have checked this and this and this non worked out/Not understanding.

Please someone help me out with steps, so that I can implement on my project.

Note : Mobile Development(Android & iOS)

Thanks in advance.

2024-12-19 12-19-39
Amal
 
MVP

Hello Rajesh

Please check the forge component "Restrict Characters mobile". This seems to provide exactly what you need. 

https://www.outsystems.com/forge/component-overview/5014/restrict-characters-mobile


UserImage.jpg
Ellakkiya

Rajesh Nadar wrote:

Hi Team,

I have a Input block with input type as Text. I want to apply regex to filter out numeric numbers and Special characters on keypress  for Mobile Development.(eg., Name inputfield must take only Alphabets)

I have checked this and this and this non worked out/Not understanding.

Please someone help me out with steps, so that I can implement on my project.

Note : Mobile Development(Android & iOS)

Thanks in advance.

Hi Rajesh Nadar,

Refer Viraj Kataria solution in this link https://www.outsystems.com/forums/discussion/43966/numeric-keyboard-that-allows-only-0-9/

you can use following javascript for only alphabets

document.getElementById($parameters.WidgetId).addEventListener("keyup", function(e){
    var patternNotOk = eval("/[^a-zA-Z]/g");
    var text = this.value.replace(patternNotOk, '');
    if (this.value != text){
        this.value = text;
    }
});


Regards.,

Ellakkiya

2018-09-06 22-01-31
Viraj Kataria

Hi Rajesh Nadar,

Screen onReady function load JavaScript:

var patternNotOk = eval("/[^a-zA-ZçÇãÃáÁàÀõÕóÓ]/g");
document.getElementById($parameters.WidgetId).addEventListener("keypress", function(e){
    var text = this.value.replace(patternNotOk, '');
    if (this.value != text){
        this.value = text;
    }
});

document.getElementById($parameters.WidgetId).addEventListener("keyup", function(e){
    var text = this.value.replace(patternNotOk, '');
    if (this.value != text){
        this.value = text;
    }
});

Hope this helps.
Thanks

UserImage.jpg
Rajesh Nadar

Hi Amal Raj ,Viraj Kataria and Ellakkiya Selvadurai ,

The suggested code does work on the Web but does not work properly on Android, When you press digits on keyboard it duplicates entered text multiple times.

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