I am looking to create a regular expression in Delphi XE that will match a number followed by one decimal point, followed by (essentially) an unlimited number of digits.
Valid examples:
2.334
150.2
0.23
3
Invalid examples:
3..42
4-2.3
e5.64
3 145
The decimal point may be optional and integers are also okay.
How would one go about doing this in Delphi using TRegEx?
Edit:
This is what I have thus far:
enter function CheckCoefficientBoxesValidInput(InputtedTerm : TEdit) : boolean;
var
RegularExpression : TRegEx;
Match : TMatch;
begin
RegularExpression.Create('[-+]?[0-9]*\.?[0-9]+');
Match := RegularExpression.Match(InputtedTerm.Text);
if Match.Success then
begin
ShowMessage('Success.');
end;
end;
Edit 2:
Trying @DavidHeffernan's code:
Function CheckCoefficientBoxesValidInput(InputtedTerm : TEdit) : boolean;
var
RegularExpression : TRegEx;
Match : TMatch;
begin
CheckCoefficientBoxesValidInput := true;
if not RegularExpression.IsMatch(InputtedTerm.Text, '[-+]?[0-9]*\.?[0-9]+') then
CheckCoefficientBoxesValidInput := false;
end;
Unfortunately this doesn't seem to be working.
RegularExpression.Create()must beRegularExpression := TRegEx.Create()