Country Configured Mobile Phone Input Mask

Hi. I am looking for an intelligent mobile phone input control that sets the input mask based on the country code of the owner. Do you currently have something like this or something close to it?


1 Reply

PO Prince Oliver Syncfusion Team September 23, 2021 05:27 AM UTC

Hi Bezhad, 

Greetings from Syncfusion support. 

Yes, we can achieve your requirement using the Mask property in the SfMaskedTextBox. We can dynamically modify the mask based on the country code selected in the dropdownlist. Kindly refer to the following code 

@using Syncfusion.Blazor.Inputs 
@using Syncfusion.Blazor.DropDowns 
 
<div class="control-label"> 
    Country code 
</div> 
        <SfDropDownList TItem="CountryCode" TValue="string" PopupHeight="230px"  Placeholder="Select a game" @bind-Value="@DropVal" DataSource="@codes" > 
            <DropDownListEvents TItem="CountryCode" TValue="string" ValueChange="OnChange"></DropDownListEvents> 
            <DropDownListFieldSettings Text="Code" Value="Code"></DropDownListFieldSettings> 
        </SfDropDownList> 
<div class="control-label"> 
    Mobile Number 
</div> 
<SfMaskedTextBox Mask="@mask"></SfMaskedTextBox> 
 
@code{ 
    public class CountryCode 
    { 
        public string Code { getset; } 
        public string Mask { getset; } 
    } 
    private List<CountryCode> codes = new List<CountryCode>() { 
        new CountryCode(){ Code= "+1", Mask= "000-000-0000" }, 
        new CountryCode(){ Code= "+44", Mask= "0000-000000" }, 
        new CountryCode(){ Code= "+91", Mask= "00000 00000" }, 
     }; 
    public string DropVal = "+1"; 
    public string mask = "000-000-0000"; 
    public void OnChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<stringCountryCode> args) 
    { 
        this.mask = args.ItemData.Mask; 
    } 
} 
 

 



Please let us know if you need any further assistance. 

Regards, 
Prince 


Loader.
Up arrow icon