Jump to content

validation using RegExp in java


Recommended Posts

hi friends..i have to validate the text box content.the text field must contain "min and max 0f 5 characters"it can take alphanumeric values alsoif it takes characters, only the first two should be allowedThe first two may be number or characterThe last 3 must be numericIe the field can take 12345 or AB123please can any one help me out the issue as soon as possiable....

Link to comment
Share on other sites

JavaScript right??? not Java :) Maybe this:

<head><script>function check(val){  if (val.length<5)alert("Too short");  else  {      var tomatch=/[A-Za-z0-9]\w{1,}[0-9]\w{2,}/          if(tomatch.test(val))        {          alert("Expression is ok")        }       else         {          alert("Expression is incorrect")        }  } }</script></head><body><input type="text" maxlength="5" id="box" /><input type="button" value="button" onclick="check(box.value)" /><body>

Blue's the regular expression expert :)

Link to comment
Share on other sites

the code is not working for this combination of input 123AB..it is accepting the above inputplease do consider this one..valid inputs are 12345, AB123,A1234,1B123the last 3 digits must be numeric...and it should not allow any special charaters.

Link to comment
Share on other sites

ok try this one :)

<head><script>function check(val){  if (val.length<5)alert("Too short");  else  {      var tomatch=/[A-Za-z0-9]\w{1,}[0-9]\d{2,}/          if(tomatch.test(val))        {          alert("Expression is ok")        }       else         {          alert("Expression is incorrect")        }  } }</script></head><body><input type="text" maxlength="5" id="box" /><input type="button" value="button" onclick="check(box.value)" /><body>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...