Reputation: 21
I have what seem to be two identical strings, which are returning different results via match. One of the strings is gathered via an input field, and the other is retrieved from local storage generated from firebase ui auth.
The regex in question is /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/
localStorage.getItem("CurrentPhone")
-> "+1(631) 894-4396"
localStorage.getItem("CurrentPhone").match(phoneRegex)
-> null
"+1(631) 894-4396".match(phoneRegex) // Copied and pasted from result of calling localStorage.getItem("CurrentPhone")
-> null
"+1(631) 894-4396".match(phoneRegex) // Typing string
-> Array(6) [ "+1(631) 894-4396", "1", "631", "894", "4396", undefined ]
Additionally, I've tried trimming the local storage result, and casting it to string directly, both with no results. Maybe I'm missing some hidden character?
Upvotes: 0
Views: 51
Reputation: 21
Solved. Issue was U+202C character which was appended on when saving to local storage. Solved by cleaning out non ASCII with localStorage.getItem("CurrentPhone").replace(/[^\x00-\x7F]/g, "")
Not sure why this was being attached, but something to look out for when dealing with firebase auth.
Upvotes: 1