parent
bb87386406
commit
17028a3f86
|
|
@ -51,6 +51,21 @@ class InputWidget extends BaseWidget<InputWidgetProps, WidgetState> {
|
|||
return {
|
||||
isValid: `{{
|
||||
function(){
|
||||
let parsedRegex = null;
|
||||
if (this.regex) {
|
||||
// break up the regexp pattern into 4 parts: given regex, regex prefix , regex pattern, regex flags
|
||||
// Example /appsmith/i will be split into ["/appsmith/gi", "/", "appsmith", "gi"]
|
||||
const regexParts = this.regex.match(/(\\/?)(.+)\\1([a-z]*)/i);
|
||||
if (regexParts === null) {
|
||||
parsedRegex = new RegExp(this.regex);
|
||||
}
|
||||
// if we don't have a regex flags (gmisuy), convert provided string into regexp directly
|
||||
if (regexParts[3] && !/^(?!.*?(.).*?\\1)[gmisuy]+$/.test(regexParts[3])) {
|
||||
parsedRegex = RegExp(this.regex);
|
||||
}
|
||||
// if we have a regex flags, use it to form regexp
|
||||
parsedRegex = new RegExp(regexParts[2], regexParts[3]);
|
||||
}
|
||||
if (this.inputType === "EMAIL") {
|
||||
const emailRegex = new RegExp(/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$/);
|
||||
return emailRegex.test(this.text);
|
||||
|
|
@ -60,16 +75,16 @@ class InputWidget extends BaseWidget<InputWidgetProps, WidgetState> {
|
|||
}
|
||||
else if (this.isRequired) {
|
||||
if(this.text && this.text.length) {
|
||||
if(this.regex) {
|
||||
return new RegExp(this.regex).test(this.text)
|
||||
if (parsedRegex) {
|
||||
return parsedRegex.test(this.text)
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} if (this.regex) {
|
||||
return new RegExp(this.regex).test(this.text)
|
||||
} if (parsedRegex) {
|
||||
return parsedRegex.test(this.text)
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user