/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cf.commonpoint;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Sanjeet Singh R
 */
public class CPValidate {
    public static String CPValidate(String rawText, String type)
    {
        int statusCode;
        /* 0-Bad Input
           1-Valid
           2-Invalid type */ 
        Matcher matcher;
        Pattern pattern = null;
        switch(type)
        {
            case "username": pattern=Pattern.compile("^[a-zA-Z0-9-_]{6,15}$");break;
            case "person-name": pattern=Pattern.compile("^[a-zA-Z]+(([',.- ][a-zA-Z ])?[a-zA-Z]*)*$");break;
            case "email" : pattern=Pattern.compile("^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@"
                +"[a-zA-Z0-9-]+(\\.[a-zA-Z0-9]+)*(\\.[a-zA-z]{2,})$");break;
            case "password": pattern=Pattern.compile("^(?=.*[0-9])(?=.*[a-z])(?=.*[A_Z]).{4,8}$");break;
            case "phone-number":pattern=Pattern.compile("^[0-9]{10}$");break;
            default: break;
        }
        if(pattern!=null)
        {
            matcher=pattern.matcher(rawText);
            if(matcher.matches())
                statusCode=1;
            else statusCode=0;
        }
        else statusCode=2;
        return rawText;
    }
    
}

@@ -341,21 +341,22 @@
    p
-ublic
+rivate
  static 
 Stri
@@ -351,22 +351,19 @@
  static 
-Str
 in
-g
+t
  CPValid
@@ -1121,32 +1121,307 @@
 %5D%7B10%7D$%22);break;%0A
+            //Jeff Ichnowski(author of the OWASP Java Encoder Project) alternate Code ?%0A            case %22URL%22: pattern=Pattern.compile(%22%5E((((https?%7Cftps?%7Cgopher%7Ctelnet%7Cnntp)://)%7C(mailto:%7Cnews:))(%25%5B0-9A-Fa-f%5D%7B2%7D%7C%5B-()_.!~*';/?:@&=+$,A-Za-z0-9%5D)+)(%5B).!';/?:,%5D%5B%5B:blank:%5D%5D)?$%22);%0A
             defa
@@ -1428,24 +1428,24 @@
 ult: break;%0A
-
         %7D%0A  
@@ -1671,23 +1671,26 @@
  return 
-rawText
+statusCode
 ;%0A    %7D%0A

Input Validation