@webex/common
Version:
Common utilities for Cisco Webex
58 lines (51 loc) • 1.81 kB
JavaScript
/*!
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
*/
/**
* @description Set of regex patterns to compile once and use throughout the
* app. All non-prefixed patterns have start/end characters to ensure exact
* matches. Patterns prefixed with "exec" are the same as their non-prefixed
* counterparts but without the start/end characters so they can be used with
* methods like `RegExp#exec`.
*/
export default {
/**
* Regular express that validates a string is strictly an email.
* Allows for validation of emails within services such as conversation
* activities or user details.
* See [RegEx information here]{@link https://ihateregex.io/expr/email-2}.
*
* @type {RegExp}
*/
email:
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
/**
* Regular expression that validates an ambiguous string contains emails
* (one or more) within.
* See [RegEx information here]{@link https://ihateregex.io/expr/email-2}.
*
* @type {RegExp}
*/
containsEmails:
/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g,
/**
* Matches a UUID
* @type {RegExp}
*/
uuid: /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/,
/**
* Regular expression that validates an ambiguous string contains MTID
* @type {RegExp}
*/
containsMTID: /(MTID=)[^&$#]*/g,
/**
* Same as this.email, but allows for surrounding characters
* @type {RegExp}
*/
execEmail: /[^\s]+?@[^\s]+?/,
/**
* Same as this.uuid but allows for surrounding characters
* @type {RegExp}
*/
execUuid: /[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}/,
};