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
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
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
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.
Nandhakumar.
Hi !
I used this regex expression in javascript widet but it was not working
If You can help
Regards
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.
Hi @Priya Kumari , I've made some changes in your OML.
Kindly, take a look.
Thanks.
Hi
I got the answer
Thanks
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
This inside the javascript right?
Yes
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 .
Hey Anshul Thankyou so much
Can you explain what you did inside the javascript please
It will be very helpful
Thankyou so much