iOS Question Mask Text Field XXX.XXX.XXX-XX

Discussion in 'iOS Questions' started by Luiz Fernando Orlandini, Feb 14, 2015.

  1. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Hi All.

    I'm trying to develop a sub to format my text field with the mask XXX.XXX.XXX-XX.

    It's acceptable only numbers. This is a point in iPad device, cause I can't discover any way to restrict the input for numbers.

    I'm using this code.

    Code:
    Sub txtDocumentNumber_TextChanged(OldText As String, NewText As String)
        
    Log ("OldText " & OldText)
        
    Log ("NewText " & NewText)
           
        
    If (DocType = "CPF"Then
            
    If (NewText.CharAt(NewText.Length - 1) = "1" OR NewText.CharAt(NewText.Length - 1) = "2" OR NewText.CharAt(NewText.Length - 1) = "3" OR _
                NewText.CharAt(NewText.Length - 
    1) = "4" OR NewText.CharAt(NewText.Length - 1) = "5" OR NewText.CharAt(NewText.Length - 1) = "6" OR _
                NewText.CharAt(NewText.Length - 
    1) = "7" OR NewText.CharAt(NewText.Length - 1) = "8" OR NewText.CharAt(NewText.Length - 1) ="9" OR _
                NewText.CharAt(NewText.Length - 
    1) = "0" OR NewText.CharAt(NewText.Length - 1) = ""Then
           
                
    If OldText.Length > NewText.Length Then
                    
    Return
                
    End If
               
                
    If (OldText.Length = 3Then
                    txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(
    03) & "." & NewText.Replace(txtDocumentNumber.Text.SubString2(03), "")
                
    Else If (OldText.Length = 7Then
                    txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(
    07) & "." & NewText.Replace(txtDocumentNumber.Text.SubString2(07), "")
                
    Else If (OldText.Length = 11Then
                    txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(
    011) & "-" & NewText.Replace(txtDocumentNumber.Text.SubString2(011), "")
                
    Else If (NewText.Length > 14Then
                    txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(
    014)
                
    End If
            
    Else
                txtDocumentNumber.Text = OldText
            
    End If
        
    End If
       
        
    Log("txtDocumentNumber " & txtDocumentNumber.Text)
    End Sub
     
  2. ilan

    ilan Expert Licensed User

    you want only be able to put numbers in the textfield??
    if yes this could help you

    Code:
    Sub TextField1_TextChanged (OldText As String, NewText As String)

        
    Dim c As String = newtext.Replace(oldtext,"")
        
    If IsNumber(c) = False Then TextField1.Text = TextField1.Text.SubString2(0,TextField1.Text.Length)

    End Sub
     
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. Andrew Lindsay

    Andrew Lindsay Member Licensed User

    Is it possible to create a custom keyboard with only the numbers, dash and enter keys?
     
  5. narek adonts

    narek adonts Well-Known Member Licensed User

    See the code below

    Code:
    Dim txtBox as TextField   
    Dim no As NativeObject=txtBox
    Dim pnl As Panel

    'Code to create panel(pnl) as custom keyboard

    no.SetField(
    "inputView",pnl)
    Narek
     
  6. ilan

    ilan Expert Licensed User

    yes, you will need a panel and 12 buttons ;)
     
  7. ilan

    ilan Expert Licensed User

    you can also try this...

    Code:
    Sub pc_Click

    Dim Id As InputDialog
    Dim ret As Int
    Id.InputType = Id.INPUT_TYPE_DECIMAL_NUMBERS
    Id.HintColor= Colors.LightGray
    Id.Hint = "Enter Price"
    Id.Input = ""
    ret = 
    Id.Show("Please enter price""Price""Ok""","Cancel"Null)

    If ret = DialogResponse.POSITIVE  Then
        
    If Id.Input = "" Then
            pc.Text = 
    "0"
        
    Else
            pc.Text = 
    NumberFormat2(Id.Input,1,2,2,False)
        
    End If
    Else
        
    Return
    End If 

    End Sub
     
    Last edited: Jun 8, 2018
  8. Mike1970

    Mike1970 Member Licensed User

    Excuse me for the probably silly question, but where is the InputDialog type in B4i V5.00?
    Thank you.
     
  9. ilan

    ilan Expert Licensed User

  10. Mike1970

    Mike1970 Member Licensed User

    Thank you for your answer.
    I've seen the Filippo's InputDialog function, even fixed by Erel. But still, with that, your sample code does not works.
    In the row
    Code:
    Dim Id As InputDialog
    the compiler still say that the type is missing.
    Is there a library to download that I'm not seeing?

    Thank you again.
     
  11. ilan

    ilan Expert Licensed User

    yes you are right, it is a mistake, i have added the b4a version of input dialog :oops:

    you can use fillipo input dialog or make your own. sorry for my mistake!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice