Skip to content

Instantly share code, notes, and snippets.

@MarQuisKnox
Created December 20, 2016 17:41
Show Gist options
  • Save MarQuisKnox/f43cc11c3725e93062c5270a71b62916 to your computer and use it in GitHub Desktop.
Save MarQuisKnox/f43cc11c3725e93062c5270a71b62916 to your computer and use it in GitHub Desktop.
Check If a String is a Valid Array
/**
* Determine if a string
* is a valid array
*
* @param string string
* @return boolean
*/
function isValidArray( string )
{
var pattern = /^\[('|")?[A-Za-z0-9]+('|")?(((,(\s+)?('|")?[A-Za-z0-9]+('|")?)+)?)\]$/ig;
return pattern.test( string );
}
@MarQuisKnox
Copy link
Author

TODO:

  1. Add support for empty values
  2. Add Unicode support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment