Tuesday 15 April 2014

function - SQL Server- pattern matching for numbers only and plus sign -


itemprop = "text">

I use the following function to clear a phone number field:

  Create the function [fnRemoveNonNumericCharacters] (@ strText VARCHAR (1000)) back as VARCHAR (1000) PATINDEX ('% [^ 0-9]%', @strteext) & gt; 0 start set @strText = STUFF (@strText, PATINDEX ('% [^ 0-9]%', @strteext), 1, '') End return @strteext end   

How to Will I modify the above mentioned pattern so that it will be kept in mind when this + symbol is an acceptable character (for international numbers)?

Thankyou

As the pattern '% [^ 0-9 +] % ', However, this number will allow plus symbols anywhere. If the first character is actually a '+' then what can you really do, and if so, then only give it a prefix for the resulting hygiene number. Here's my implementation:

  Function [fnRemoveNonNumericCharacters] (@ strText VARCHAR (1000)) VARCHAR (1000) Let's begin declaring as @index integer announcement @hasPlus @strText = LTRIM Set bit (@strText) if set ('+' = left = (@strText, 1)) start @hasPlus = 1 start another end set @hasPlus = 0 end set @index = PATINDEX ('% [^ 0-9] % ', @strText) WHILE @ index & gt; 0 set set @strText = STUFF (@strText, @index, 1, '') Set @index = PATINDEX ('% [^ 0-9]%', @strteext) End if set (1 = @hasPlus) set @ StrText = '+' + @strtext End Return @ Strette END    

No comments:

Post a Comment