Android Question isNumber and cell phone number

peacemaker

Expert
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:
B4X:
Sub isNumber3(s As Object) As Boolean
    Dim str As String = s
    If IsNumber(str) Then
        If str.StartsWith("+") Then
            Return False
        Else
            Dim d As Double = str
            Return d <> d + 1
        End If
    Else
        Return False
    End If
End Sub
?

B4X:
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
        Else
            If fvalue.Contains(".") Then
                ftype = DBUtils.DB_REAL
            Else
                ftype = DBUtils.DB_INTEGER
            End If
        End If
        ft.Put(field, ftype)
    Next
    DBUtils.CreateTable(SQL, TableName, ft, "rowid", True)    'table in DB
End Sub
 

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).
 

peacemaker

Expert
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 ?
 
Top