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 ?
Solved! Go to Solution.
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
)
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.
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 2:
ankjnkjnj@foundation.com; kjkjhkjhkj@lthill.com; kjiuhiuhiu@pembroke.com
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.
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:
sample 2:
mklkml@
sample 3:
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.
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.
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
)
Thank you so much @RandyHayes
I am able to validate my mail ids with this for all cases.Thanks again.
Excellent! Sorry I got a little confused along the way. Glad it is working for you now.
User | Count |
---|---|
144 | |
97 | |
89 | |
78 | |
56 |
User | Count |
---|---|
194 | |
185 | |
105 | |
99 | |
91 |