Hi,

I am trying to validate input using the  IdentityValidationUtil[1] class.
>From my current understanding in order to validate an input using the util
class for a regex, we need to first register it as a pattern in
IdentityValidationConfig and then use the registered key as below,

String regex = "^[A-Za-z0-9]+$";
String input = "thisismainput";


// add pattern to IdentityValidationConfig
IdentityValidationUtil.addPattern("my-regex", regex);
String validInput =
IdentityValidationUtil.getValidInputOverWhiteListPatterns(input,
"my-regex");


When many of the components start using the util class there is a
possibility of the same key being registered for two different regexes
resulting in an exception thrown according to [2]. Wouldn't it be better if
we allow the users to directly provide the regex for validation instead of
having to register it with a key and use for validation.

So if  you want to use one of the pre-defined regexes you can use the
relevant key (something like ALPHABETIC_ONLY) defined in class[1]. Or If
you want to use his own regex you can simply provide it as a whitelist
pattern.

In the code, we can first check if the provided value is a predefined key,
if so fetch the regex and validate. If the key is not found then we have
given the regex directly, so we can use it directly to validate. This
approach is used it the JavaScript util class we have written[3].

WDYT?


[1]
https://github.com/wso2/carbon-identity-framework/blob/master/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityValidationUtil.java
[2]
https://github.com/wso2/carbon-identity-framework/blob/master/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityValidatorConfig.java#L58
[3]
https://github.com/wso2/carbon-identity-framework/blob/master/components/identity-core/org.wso2.carbon.identity.core.ui/src/main/resources/web/identity/validation/js/identity-validate.js

Farasath Ahamed
Software Engineer, WSO2 Inc.; http://wso2.com
Mobile: +94777603866
Blog: blog.farazath.com
Twitter: @farazath619 <https://twitter.com/farazath619>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to