352
Views
13
Comments
Solved
Phone Number validation

Hi Everyone

I am doing a reactive web application to store the data of an employee locally (I am not using database .. I am using structures) , while storing the phone number I need to validate it . The phone number should not contain  alphabits and special charecters  and it should only contain 10 digits . I am using javascript and regix expression but I am not able to find a suitable regex expression and how to use it in javascript.


It will be very helpfull if someone will help me  regarding this 

Regards,

Priya

2023-04-18 10-31-31
Anshul Jain
Solution

Hi Priya

Glad you found this helpful. Basically what I did was replaced every character that matched our given regex pattern ( ^0-9 means any character which is not a number ) with an empty text ('') using the replace method.

And then used the returned text from the replace method as the output variable of the Javascript node and then assigned the value of our original variable (which was being used in the input widget) as the value of the output variable of the Javascript node. 

So every non-number input in the input widget got converted as empty text ('') and hence we only got numbers in the input widget and in the original variable value.

Thanks,

Anshul

2023-04-18 10-31-31
Anshul Jain
Solution

Hi Priya

I was under the assumption that you wanted to validate the phone number on some sort of save action but after going through the oml file you shared I understood your requirement correctly.

I have updated your OML please have a look


Thanks,

Anshul

Emp_UI.oml
2025-12-12 06-45-53
Nandhakumar Sureshbabu

Hi @Priya Kumari ,

"^[789]\d{9}$ " you can use this regex expression or else you can directly utilize the outsystems default validation i.e Mobile number data type but the ousystems default db length for mobile number is 20. 

if you're going with js validation it's also totally fine, you can achieve that using javascript widget for that. You can also use regex in server action (You can find that by using dependencies in text(extension))

Hope this helps.

Regards,

Nandhakumar.

UserImage.jpg
Priya Kumari

Hi !

I used this regex expression in javascript widet but it was not working

If You can help


Regards 

Priya 

2025-12-12 06-45-53
Nandhakumar Sureshbabu

use this expression in your js widget "

/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im.test($parameters.In1);" instead of  paramaters.In1 replace it with your output parameter.

Hope this helps. 

2025-12-12 06-45-53
Nandhakumar Sureshbabu


Hi @Priya Kumari , I've made some changes in your OML.

 Kindly, take a look.

 Thanks.

Emp_UI_modified.oml
UserImage.jpg
Priya Kumari

Hi 

I got the answer 

Thanks

2023-04-18 10-31-31
Anshul Jain

Hi Priya

Use "/^[0-9]+$/" as your regex expression like this:

var numberRegex = /^[0-9]+$/;

$parameters.IsValid = numberRegex.test($parameters.PhoneNumber);

This will return you a boolean result that will tell you whether the input contains all numbers or not.

For the phone number to contain exactly 10 digits validation you can use the Length() method provided by Outsystems

Thanks,

Anshul

UserImage.jpg
Priya Kumari

This inside the javascript right?

UserImage.jpg
Priya Kumari


Hey I am attaching my oml can you please check and tell me where I am making mistake ?

Because as you mentioned in the previous comment I made the changes but still  It was accepting the alphabits .

Emp_UI.oml
2023-04-18 10-31-31
Anshul Jain
Solution

Hi Priya

I was under the assumption that you wanted to validate the phone number on some sort of save action but after going through the oml file you shared I understood your requirement correctly.

I have updated your OML please have a look


Thanks,

Anshul

Emp_UI.oml
UserImage.jpg
Priya Kumari

Hey Anshul Thankyou so much 

Can you explain what you did inside the javascript please 

It will be very helpful


Regards,

Priya

2023-04-18 10-31-31
Anshul Jain
Solution

Hi Priya

Glad you found this helpful. Basically what I did was replaced every character that matched our given regex pattern ( ^0-9 means any character which is not a number ) with an empty text ('') using the replace method.

And then used the returned text from the replace method as the output variable of the Javascript node and then assigned the value of our original variable (which was being used in the input widget) as the value of the output variable of the Javascript node. 

So every non-number input in the input widget got converted as empty text ('') and hence we only got numbers in the input widget and in the original variable value.

Thanks,

Anshul

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