We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dynamic Masks for Credit Cards

Hello, I'm working on a basic credit card form entry page and I need to support masks for Visa and AMEX.

I want to update the mask when a user inputs certain characters. This check should happen after each character is typed, something like this:

if (e.DataFormItem.Name.Equals("CardNumber"))
                        (e.DataFormItem as DataFormMaskedEditTextItem).KeyBoard = Keyboard.Numeric;
                        (e.DataFormItem as DataFormMaskedEditTextItem).MaskType = Syncfusion.XForms.MaskedEdit.MaskType.Text;

                        if (e.DataFormItem.LabelText.StartsWith("34") || e.DataFormItem.LabelText.StartsWith("37"))
                            (e.DataFormItem as DataFormMaskedEditTextItem).Mask = @"0000 000000 00000";

                            (e.DataFormItem as DataFormMaskedEditTextItem).Mask = @"0000 0000 0000 0000";

The problem here is that the mask is only set once when the dataform is auto generated.
Is there a way to do this with SfDataForm? Thanks!

1 Reply

AK Ajith Kumar Senthil Kumar Syncfusion Team November 19, 2019 07:08 PM UTC

Hi Marcus Bowyer, 
Thank you for contacting Syncfusion support.  
Based on the provided information, your requirement is “To change Mask property of DataFormMaskedItem dynamically” in Xamarin.Forms. Currently we don’t have support to change the mask property in run time, but it can be achieved using the RefreshLayout method in any of event where the condition check needs to be happened. 
Please refer the following code example for the same, 
We hope this helps. Please let us know, if need any further assistance. 

Live Chat Icon For mobile
Up arrow icon