IsNumeric allows below special characters
`SELECT ISNUMERIC('10.50') as '10.50'
ISNUMERIC('10,50') as '10,50'
,ISNUMERIC('-') as '-'
,ISNUMERIC('+') as '+'
,ISNUMERIC('$') as '$'
,ISNUMERIC('.') as '.'
,ISNUMERIC(',') as ','
,ISNUMERIC('\') as '\'`
So, I wanted to use RegEx https:// regexr.com/4gjhm to validate my numeric which must allow numbers and dot only.
Tried Regex ^[0-9]+[.]{0,1}[0-9]*$ with the help of PATINDEX, but didn't get the expected results
`DECLARE @Amount As NVARCHAR(50) = '150';
SELECT CASE
WHEN @Amount LIKE '%^[0-9]+[.]{0,1}[0-9]*$%'
THEN 1
ELSE 0
END AS IsNumericResult`
Valid Ex: 10, 10.01, .20 Invalid Ex: 10.50.20, 10..20, etc
Is this possible to achieve through LIKE or PATINDEX in SQL Server 2017?
%^ ...$%seems a bit contradictory to me.ISNUMERIC()won't help there as you already state, instead you can useTRY_CAST() / TRY_CONVERT(). Without the needs to Regex.numericwithout error or some other reason?[0-9]or set[01234]you can't use+or*to match an instictinct count of them. Ie something like[0-9]+will match1+but not123. So you might be best off with @Sami answer and add some additional tests to exclude for instance+123or-1.5