SubName: ValidNumber
Description: A multi purpose number validator
Dependencies: None
Tags: Number Validator
The attached project for B4j shows the use I wrote it for with error reporting.
This requires CSSUtils.
Description: A multi purpose number validator
B4X:
Private Sub ValidNumber(Str As String, Negative As Boolean, Decimal As Boolean) As Boolean
If Str = "" Then Return False
Dim RegexStr As StringBuilder
RegexStr.Initialize
If Negative Then RegexStr.Append("-?")
If Decimal Then
RegexStr.Append("[0-9]*\.[0-9]*|")
If Negative Then RegexStr.Append("-?")
End If
RegexStr.Append("[0-9]*")
Return Regex.IsMatch(RegexStr.ToString,Str)
'Complete Regex String for all tests "-?[0-9]*\.[0-9]*|-?[0-9]*"
End Sub
Dependencies: None
Tags: Number Validator
The attached project for B4j shows the use I wrote it for with error reporting.
This requires CSSUtils.
Attachments
Last edited: