cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chauhanhardik
Frequent Visitor

validate field value with RegEx on field focusOut

Hi Community,

 

I have scenario in PowerApps portals where I need your help.

 

while creating a record through Basic form(earlier Entity form), I want to verify field value once user moves out of field (before user clicks submit button). Any idea how can I do this?

 

I wrote code as below, but it's not working:

$("#nt_pannumber").focusout(function () {
    //$(this).css("background-color", "#FFFFFF");

    // Regular expression with Indian PAN format
    var regExp = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
    var panValue = $("#nt_pannumber").val();
    alert(panValue);
    if (panValue.search(regExp) == -1) {
        alert("Invalid PAN number format");
    }
});

 

Please suggest me how to do this.

 

Thanks!

Hardik

1 REPLY 1
NatGeo
Helper I
Helper I

Hi @chauhanhardik ,

 

To achieve this functionality I would do the following:

1. add validation on blur

'$("#your_filed").blur(function(){

var regExp = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
var isInvalid = !regExp.test(inputValue);
}'

2. add validation on submit as well

Add custom JavaScript - Power Apps | Microsoft Docs

 

Hoping it helps.

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,394)