Showing posts with label Regular Expressions. Show all posts
Showing posts with label Regular Expressions. Show all posts

Java Script Validation for UserName

Alphabets, numbers and space(' ') no special characters min 3 and max 20 characters.
Starts with an Alpahbet.

var ck_name = /^[A-Za-z][A-Za-z0-9 ]{3,20}$/;

functiuon test()
{
    ck_name.text(username) == true;
}

Regular Expressions

Always use PROPER Regular Expression for Validations both in JSP and Servlet.
This saves time, efficiency and Code.

Before passing to the regEx just check the null validation and that's it. Yours all.

public boolean isNumeric(String stringValue) {
if(stringValue != null)
{
Pattern pattern = Pattern.compile( "\\d+" );
Matcher matcher = pattern.matcher(stringValue);
return matcher.matches();
}
else
{
return false;
}
}

RegEx for checking a String is Numeric or not.