How to restrict the number of input in masked edit inside the Xamarin.Forms SfTextInputLayout?
The number of input lengths in Xamarin.Forms Syncfusion SfMaskedEdit has been limited by using the Text and Regular Expression. In Xamarin.Forms TextInputLayout, you can do the same with SfTextInputLayout by using the CharMaxLength property.
This article explains how to obtain the same ChartMaxLength support when having the masked edit as InputView of SfTextInputLayout as shown in the following code sample.
[XAML]
<StackLayout VerticalOptions="Center"> <textinputlayout:SfTextInputLayout x:Name="inputLayout" Hint="Enter credit card number" CharMaxLength="12"> <maskedEdit:SfMaskedEdit MaskType="RegEx" Mask="{Binding MaskChar}" Keyboard="Numeric" ValidationMode="KeyPress"/> </textinputlayout:SfTextInputLayout> </StackLayout>
[C#]
public partial class MainPage : ContentPage { private string maskChar; public string MaskChar { get { return maskChar; } set { maskChar = value; OnPropertyChanged("MaskChar"); } } public MainPage() { InitializeComponent(); BindingContext = this; MaskChar = @"\d{0,"+ this.inputLayout.CharMaxLength + "}"; } }
See also
What are mask types in SfMaskedEdit
How to hide the prompt character
How to hide the clear button in SfMaskedEdit
Conclusion
I hope you enjoyed learning about how to restrict the limited input values in Xamarin.Forms TextInput Layout.
You can refer to our Xamarin.Forms Text Input Layout feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications. You can also explore our Xamarin.Forms Text Input Layout example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!