Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
how to validate in javascript to accept numbers and alphabets but should not accept only numbers and special character "/" example:it can be of "12/90,annanagar" but it should not be as "12/" or "12"..can anyone help me to do this in javascript
 

code i tried:
var addresspat=/^(@"[^\d\/]")$/;
          var address=document.getElementById("<%=txtAddr.ClientID%>").value;
         var matchArray =  address.match(addresspat);
         if (matchArray == null)
   {
   }
   else{
              alert("Enter The Correct Address");
              document.getElementById("<%=txtAddr.ClientID%>").focus();
              return false;
   }
Posted 26-Mar-13 16:14pm
Edited 26-Mar-13 16:43pm
v2
Comments
ThePhantomUpvoter at 26-Mar-13 21:30pm
   
Sure. Post the code that you have tried and describe the problem with your code.
Surendra0x2 at 26-Mar-13 22:47pm
   
Check Regex like [a-zA-Z0-9] with Custom Validator

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello Nityasri,
 
Is it very much essentials that your address must start with numbers followed by a slash then numbers? If so then try with
var PAT_CHECK = /(\d+\/\d+).*/g
var ret = val.match(PAT_CHECK);
if (ret == null)
    alert("Invalid address!");
 
Regards,
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100