cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JayashreeKrish
Resolver II
Resolver II

Email Validation with specific domains in canvas App

I have a canvas app. I have a multiline field.

It is an email field. A user can enter  one or many email ids . Each id will be separated by semicolon.

 

I want to validate the email ids such that they end with either of these domain.

@lthil.com
@fpcapital.com
@thecrosbyco.com
@PBR.com
@foundation.org
@novoed.com

 

I am able to validate for one id using this regex.

/^\w+([\.-]?\w+)*(@lthill.com|@fcapital.com|@thecrosbyco.com|@pbr.com|@foundation.org|@novoed.com)+$/

 

How do I validate when several ids are entered separated by semicolon ?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@JayashreeKrish 

No problem at all.

 

Yes, the formula was written around what your original formula logic was (or at least how I perceived it).  That was - the input could be blank and then Edit OR one of the domains in the input needed to be in the accepted list, then Edit.

 

So, are you stating then that ALL of the emails in the input must be in the accepted domain list?

 

If that is the case, then the formula should change to:

If(
    IsBlank(DataCardValue9.Text) ||
    With({_emls: Filter(Split(DataCardValue9.Text, ";"), !IsBlank(Result)),
          _valids: "|lthills.com|fprimecapital.com|thecrosbyco.com|pembrokes.com|foundations.org|novoed.com|"},

        Sum(
            ForAll(_emls, 
                If("|" & Last(Filter(Split(Result, "@"), !IsBlank(Result))).Result & "|" in _valids, 1, 0)
            ), 
            Value
        ) = CountRows(_emls)
    ),
    Edit,
    Disabled
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

10 REPLIES 10
RandyHayes
Super User
Super User

@JayashreeKrish 

Utilize the Split function to split your input, then use that against your match.

If you struggle getting that working, then provide the formula you are currently using (in its entirety) for additional help.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you @RandyHayes 

 This is the formula I am using (I am disabling the button if it is not matching this pattern) 

 

 

If(
!IsBlank(DataCardValue9.Text) && !IsMatch(DataCardValue9.Text,"^\w+([\.-]?\w+)*(@lthill.com|@fprimecapital.com|@thecrosbyco.com|@pembroke.com|@foundation.org|@novoed.com)+$",MatchOptions.Complete),DisplayMode.Disabled,
DisplayMode.Edit
)

 

 

Sample Input :

 

Sample 1 :

abscdf@lthill.com

 

Sample 2:

ankjnkjnj@foundation.com; kjkjhkjhkj@lthill.com; kjiuhiuhiu@pembroke.com

RandyHayes
Super User
Super User

@JayashreeKrish 

Please consider changing your Formula to the following:

If(
    IsBlank("DataCardValue9.Text") ||
    With({_emls: Split(DataCardValue9.Text, ";"),
          _valids: "lthills.com|fprimecapital.com|thecrosbyco.com|pembrokes.com|foundations.org|novoed.com"},

        Sum(
            ForAll(_emls, 
                If(Last(Split(Result, "@")).Result in _valids, 1, 0)
            ), 
            Value
        )>0 
    ),
    Edit,
    Disabled
)

This should provide what you are looking for.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thanks @RandyHayes 

But my use case is - it is a non mandatory field,

The button should be enabled  under following conditions

1) if email field is empty or 

2)  if email values ends with either of these domains 

@lthill.com|@fcapital.com|@thecrosbyco.com|@pbr.com|@foundation.org|@novoed.com

But if I enter, For the below samples also,It shows the button enabled, But I want my button to be disabled in this case

 

sample 1: 

mkm@gmail.com; 

 

sample 2:

mklkml@

 

sample 3:

mklkml@;raj@gmail.com;

 

 

RandyHayes
Super User
Super User

@JayashreeKrish 

Well the issue with the blank part is that I accidentally had quotes around the DataCardValue9.  Sorry for that mistake.  I had vetted your formula out with hard entered values and when I went back to replace those with DataCardValue9, I overlooked the quotes.

 

I tested the formula out and do not see an issue with the blank part at this point.  If the input is blank, then the button is enabled.

 

As for a couple of other little things I noticed, here is a change to the original formula to implement.  It accounts for blank domains and a more exact match on the domain name:

If(
    IsBlank(DataCardValue9.Text) ||
    With({_emls: Filter(Split(DataCardValue9.Text, ";"), !IsBlank(Result)),
          _valids: "|lthills.com|fprimecapital.com|thecrosbyco.com|pembrokes.com|foundations.org|novoed.com|"},

        Sum(
            ForAll(_emls, 
                If("|" & Last(Filter(Split(Result, "@"), !IsBlank(Result))).Result & "|" in _valids, 1, 0)
            ), 
            Value
        )>0 
    ),
    Edit,
    Disabled
)

 

See where that takes you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thanks again. @RandyHayes 

Now I am getting a knack of it.

Still if i give a valid one and non valid one , the button is enabled.

 

mklmlkm@lthill.com;kjiuhiu@gmail.com;

 

For the above input it should be disabled , still it is enabled.

I am finding a little bit difficulty in tweaking the code and that's why reaching again.Appologies.

RandyHayes
Super User
Super User

@JayashreeKrish 

No problem at all.

 

Yes, the formula was written around what your original formula logic was (or at least how I perceived it).  That was - the input could be blank and then Edit OR one of the domains in the input needed to be in the accepted list, then Edit.

 

So, are you stating then that ALL of the emails in the input must be in the accepted domain list?

 

If that is the case, then the formula should change to:

If(
    IsBlank(DataCardValue9.Text) ||
    With({_emls: Filter(Split(DataCardValue9.Text, ";"), !IsBlank(Result)),
          _valids: "|lthills.com|fprimecapital.com|thecrosbyco.com|pembrokes.com|foundations.org|novoed.com|"},

        Sum(
            ForAll(_emls, 
                If("|" & Last(Filter(Split(Result, "@"), !IsBlank(Result))).Result & "|" in _valids, 1, 0)
            ), 
            Value
        ) = CountRows(_emls)
    ),
    Edit,
    Disabled
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you so much @RandyHayes 

I am able to validate my mail ids with this for all cases.Thanks again.

RandyHayes
Super User
Super User

@JayashreeKrish 

Excellent!  Sorry I got a little confused along the way.  Glad it is working for you now.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

<
Users online (2,402)