iOS Question SubString2 not working well on ios 8

Discussion in 'iOS Questions' started by Shay, Feb 26, 2015.

  1. Shay

    Shay Well-Known Member Licensed User

    Strange thing
    I have the code below which limit phone number to 10 digits
    on IOS 7 it is working fine, it is limiting the number to 10 numbers
    on IOS 8, I managed to enter 11 digits (maybe even 12, I don't have the DB in front of me)

    Code:
    Sub EditText6_TextChanged (Old As String, New As String)

        
    If New.Length > 10 Then
         EditText6.Text = New.SubString2(
    010)
        
    End If
       
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not related to Substring.
    It is related to how the internal text field handles the text update.

    This code should work:
    Code:
    Sub TextField1_TextChanged (OldText As String, NewText As String)
       CallSubDelayed(Me, 
    "CutText")   
    End Sub

    Sub CutText
       
    If TextField1.Text.Length > 10 Then
      TextField1.Text = TextField1.Text.SubString2(
    010)
      
    End If
    End Sub
     
  3. Shay

    Shay Well-Known Member Licensed User

    How can I make this generic
    meaning if I have many TextFieldXXX with sizes YYY
     
  4. stevel05

    stevel05 Expert Licensed User

    Try this:

    Code:
    Sub TextField1_TextChanged (OldText As String, NewText As String)
       CallSubDelayed3(Me, 
    "CutText",TextField1,10)  
    End Sub
    Sub CutText(Tf As TextField,MaxLength As Int)
        
    If Tf.Text.Length > MaxLength Then
            Tf.Text = Tf.Text.SubString2(
    0,MaxLength)
        
    End If
    End Sub
     
    Erel and boastrike like this.
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