Hi,
I am using SAP UI5 .
I am validating the user input using a regular expression to make sure user dose not enter a keyword which is reserved.
var regexAppID = /^(?=^(?:(?!(^Admin$|^AdminData$|^Push$|^smp_cloud$|^resource$|^test-resources$|^resources$|^Scheduler$|^odata$|^applications$|^Connections$|^public|^Public$|[\.]{2,}|^[\.])).)*$)(?=^[a-zA-Z]+[a-zA-Z0-9_\.]*$).*$/;
textField.mBindingInfos.value.type.oConstraints.search = regexAppID;
The regex blocks the user from entering the keywords Admin,AdminData etc.
It works fine if the user enters the value as it is given in regex (ie case sensitive example "Admin").
But when user enters "admin" or "aDmin" etc the regex is not catching it and my server crashes as it bypasses these keywords.
Request clarification before answering.
Why don't you just use this?
/Admin|AdminData|resource|test-resources|resources|Scheduler|applications|public|Public/i
The i will ignore all cases.
You can generate regex:
JavaScript Lab - Tools - JS Regex Generator
And for testing you can use this:
Rubular: a Ruby regular expression editor and tester
Kind regards,
Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wouter,
Using "/i" like below works fine. It restricts the words.
var regEx = /^(?=^(?:(?!(^Admin$|^AdminData$|^Push$|^smp_cloud$|^resource$|^test-resources$|^resources$|^Scheduler$|^odata$|^applications$|^Connections$|^public|^Public$|[\.]{2,}|^[\.])).)*$)/i;
But when I add (?=^[a-zA-Z]+[a-zA-Z0-9_\.]*$).*$/ to above which allow user to enter any string with starting alphabet, it gives me syntax error.
var regEx = /^(?=^(?:(?!(^Admin$|^AdminData$|^Push$|^smp_cloud$|^resource$|^test-resources$|^resources$|^Scheduler$|^odata$|^applications$|^Connections$|^public|^Public$|[\.]{2,}|^[\.])).)*$)/i (?=^[a-zA-Z]+[a-zA-Z0-9_\.]*$).*$/ ;
Can't you use this expression?
^/(?!ignoreme$)(?!ignoreme2$)[a-z0-9]+$
Then you will have only a match when the word is something else then "ignoreme" or "ignorme2".
Why don't you just check it in an IF statement? if(input==="ignoreme" or ... ) ? It's both static.. or you could put all options in an array and use the statement indexOf to find if it is in the array.
JavaScript Array indexOf() Method
Kind regards,
Wouter
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.