how to enable only numbers keypad(without dot(.) ) in both android and iOS device??

ShettyAshShettyAsh Member ✭✭✭

hi,
I wanted to validate user entry is Number... i used keyboard="Numeric" but it takes dot(.) also..i want to remove this .
Also in iOS device keyboard="Numeric" doesn't work i.e it also takes string text.
Please help me with this

Thanks

Best Answers

Answers

  • BhautikBhautik Member ✭✭✭

    @ColeX said:
    I made it work via Custom renderer .

    iOS

    [assembly:ExportRenderer(typeof(Entry),typeof(MyEntryRenderer))]
    namespace FormsApp.iOS
    {
        class MyEntryRenderer : EntryRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
    
                if(Control != null){
                    Control.KeyboardType = UIKeyboardType.NumberPad;
                }
            }
        }
    }
    

    Android

    [assembly: ExportRenderer(typeof(Entry), typeof(MyEntryRenderer))]
    namespace App1.Droid
    {
        class MyEntryRenderer :EntryRenderer
        {
            public MyEntryRenderer(Context context) : base(context)
            {
            }
    
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
                if(Control != null)
                {
                    Control.InputType = InputTypes.ClassNumber | InputTypes.NumberVariationPassword;
                }
            }
        }
    }
    

    It is working as expected on iOS mobile devices but not on iPad. :neutral:

Sign In or Register to comment.