Open honzahana opened 3 years ago
You can just do Str::of('foo')->replaceMatches('/[\s]+/mu', '')
, anyway I feel like opening a PR would be more effective
Some countries may type phone numbers and zip-codes as 012-345-6789.
Wouldn't it be better to have a function like extractNumber()
That removes everything except digits?
I feel like that would be more general and fit your requirements.
Extracting phone numbers was an example. It is also useful for removing spaces from VAT IDs, Company Registration Numbers (EU), postcodes, credit card numbers and so on.
Please add
removeSpaces
toStr
helper and Fluent String. This is especially useful for sanitizing phone numbers and zip codes.Regex based on: https://stackoverflow.com/a/58252825
Discussed here: https://laracasts.com/discuss/channels/laravel/extend-str-helper