1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Extend typedInput "num" type validity check to NaN, binary, octal & hex

This commit is contained in:
ralphwetzel 2023-09-26 20:00:48 +02:00
parent ee48a2f2bf
commit 5ac50fae3a
2 changed files with 4 additions and 2 deletions

View File

@ -182,7 +182,9 @@
valueLabel: contextLabel valueLabel: contextLabel
}, },
str: {value:"str",label:"string",icon:"red/images/typedInput/az.svg"}, str: {value:"str",label:"string",icon:"red/images/typedInput/az.svg"},
num: {value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/}, num: {value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate: function(v) {
return (true === RED.utils.validateTypedProperty(v, "num"));
} },
bool: {value:"bool",label:"boolean",icon:"red/images/typedInput/bool.svg",options:["true","false"]}, bool: {value:"bool",label:"boolean",icon:"red/images/typedInput/bool.svg",options:["true","false"]},
json: { json: {
value:"json", value:"json",

View File

@ -921,7 +921,7 @@ RED.utils = (function() {
error = RED._("validator.errors.invalid-prop") error = RED._("validator.errors.invalid-prop")
} }
} else if (propertyType === 'num') { } else if (propertyType === 'num') {
if (!/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(propertyValue)) { if (!/^NaN$|^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$|^[+-]?(0b|0B)[01]+$|^[+-]?(0o|0O)[0-7]+$|^[+-]?(0x|0X)[0-9a-fA-F]+$/.test(propertyValue)) {
error = RED._("validator.errors.invalid-num") error = RED._("validator.errors.invalid-num")
} }
} else if (propertyType === 'jsonata') { } else if (propertyType === 'jsonata') {