Android Question isNumber and cell phone number

Discussion in 'Android Questions' started by peacemaker, Nov 1, 2018.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    HI, All

    It seems to me, that phone number like "+41987654321" - is not a number for the database, but isNumber function = True.

    Trouble is that SMS cannot be sent to a number "41...", "+41..." is required.
    Any ideas to solve ?

    Noting this post, maybe:
    Sub isNumber3(s As Object) As Boolean
    Dim str As String = s
    If IsNumber(str) Then
    If str.StartsWith("+"Then
    Return False
    Dim d As Double = str
    Return d <> d + 1
    End If
    Return False
    End If
    End Sub

    Sub JSON_CreateTableStructure(SQL As SQL, TableName As String, RowMap As Map)
    If RowMap.IsInitialized = False Then Return
    If RowMap.Size = 0 Then Return
    Dim ft As Map:ft.Initialize
    Dim field, ftype, fvalue As String
    For i = 0 To RowMap.Size - 1
            field = RowMap.GetKeyAt(i)
            fvalue = RowMap.GetValueAt(i)
    If isNumber3(fvalue) = False Then
                ftype = DBUtils.DB_TEXT
    If fvalue.Contains("."Then
                    ftype = DBUtils.DB_REAL
                    ftype = DBUtils.DB_INTEGER
    End If
    End If
            ft.Put(field, ftype)
    SQL, TableName, ft, "rowid"True)    'table in DB
    End Sub
  2. udg

    udg Expert Licensed User

    IMHO, isNumber correctly returns True for "+41987654321" because the plus sign indicates a positive number.
    I can't understand why you'd like to store a telephone number as a numeric value instead of a string/text, if that's your goal (in fact, I'm not sure to have understood it correctly).
    BillMeyer likes this.
  3. peacemaker

    peacemaker Well-Known Member Licensed User

    Task is automatically recognize the field type for the database table creation. And phone number must be String type (for preserving +), but isNumber formally.
    How to detect correctly ?
  4. udg

    udg Expert Licensed User

  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