Android Question XUI Views

Declan

Well-Known Member
Licensed User
Longtime User
I am using the following code to allow the user to enter data using an Input dialog from XUI Views.
How can I "force" a ten digit number - only ten - no more, no less :cool:
Only after the tenth digit is entered, does the "OK" become enabled.
I have tried:
B4X:
input.RegexPattern = ".........." 'require at least one character
This somewhat works, but the user can enter in excess of ten digits.

My Code:
B4X:
    Dim input As B4XInputTemplate
    dialog.Initialize(Activity)
    dialog.Title = "Lead Guru"
    input.Initialize
    input.lblTitle.Text = "Enter your phone number:"
    input.ConfigureForNumbers(True, True)
    input.RegexPattern = ".+" 'require at least one character
    Wait For (dialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        LogColor("Pressed Dialog OK", Colors.Magenta)
    End If
 

Declan

Well-Known Member
Licensed User
Longtime User
Try this:
B4X:
Input.RegexPattern = ("^\d{10}")
The "OK" is enabled on the input of the tenth digit, but user can still enter more than 10 digits.
I must limit the length of the input to 10 digits - to avoid possible errors
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I must limit the length of the input to 10 digits - to avoid possible errors
yes, but the OK is grayed out again and disabled if they put more than 10, so they have to remove the additional digits. The entry is not accepted unless they have 10 digits.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I must limit the length of the input to 10 digits
And if you want to use the numbers keyboard only, here it is more complete:
B4X:
Dim IME As IME
    IME.Initialize("IME")
    Input.Initialize
    IME.SetLengthFilter(Input.TextField1,10)  'to limit the number of digits to only 10. They cannot type more than 10
    Dim et As EditText =Input.TextField1
    et.InputType = et.INPUT_TYPE_NUMBERS
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
@Mahares
@Erel
Awesome - Thanks Guys
You will notice from the below code that I am using the mobile number as the Firebase topic.
B4X:
    Dim input As B4XInputTemplate
    dialog.Initialize(Activity)
    dialog.Title = "Lead Guru"
    
    Dim IME As IME
    IME.Initialize("IME")
    
    input.Initialize
    input.lblTitle.Text = "Enter your phone number:"
    input.ConfigureForNumbers(True, True)
    'input.RegexPattern = ".+" 'require at least one character
    
    IME.SetLengthFilter(input.TextField1,10)
    
    input.RegexPattern = ("^\d{10}")
    Wait For (dialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        LogColor("Pressed Dialog OK", Colors.Magenta)
        LogColor(input.Text, Colors.Magenta)
    '    Starter.DB.ExecNonQuery2("INSERT INTO user",Array As String VALUES(MyTel))
        Starter.DB.ExecNonQuery2("INSERT INTO user VALUES(?)", Array As String(input.Text))
        LogColor("Inserted OK", Colors.Magenta)
        
        'Firebase
        FBtopic = input.Text
        CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
    End If
 
Upvote 0
Top