Created
April 30, 2020 12:03
-
-
Save banzeh/775303d7b91e1ac6e4bf18f8791d7079 to your computer and use it in GitHub Desktop.
Função em TS com Regex para validar JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public validateJSON(text: string): boolean { | |
return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( | |
text.replace(/"(\\.|[^"\\])*"/g, ''))) && | |
eval('(' + text + ')'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment