JavaScript - regular expression for alphanumeric ( ) , ' @ - . also spac

Asked By theiry henry on 01-Oct-10 06:07 AM
plz ny 1 help me out for writing  a regular expression for alphanumeric character with some additional character like 

(  ) , ' @ - . also space

plz giv me d regular expression this character can come more than once in the word
Sagar P replied to theiry henry on 01-Oct-10 06:15 AM
TRY this regular expression;

^[a-zA-Z0-9 -()@,.]*$

testing and working fine for alphanumeric character with some additional character like  (  ) , ' @ - . also space
Web Star replied to theiry henry on 01-Oct-10 06:16 AM
You can use this expression for that

validationexpression="[0-9a-zA-Z' '(  ) , ' @ - .]
Rohan Dave replied to theiry henry on 01-Oct-10 06:18 AM
Hey try  below javascript function..

function IsalphaNumeric(Yourtxt)

if(Yourtxt.length == 0 || Yourtxt.search(/[^a-zA-Z0-9 ]$/()/'/@/-/,/ /) != -1 ) 
 return false; 
else
 return true;
}


Let us know if it will not work for you...
theiry henry replied to Sagar P on 01-Oct-10 06:44 AM
tnx a lot
_ash_ k replied to theiry henry on 01-Oct-10 06:58 AM
The below syntax matches 0 or more occurances of alphanumeric values together with the additional characters
 
[a-zA-Z0-9(),'@- ]*

You can find more details on the usage of teh reg expressions at
http://www.javascriptkit.com/javatutors/re2.shtml

Hope this helps.

_ash_

mv ark replied to theiry henry on 01-Oct-10 07:26 AM
Try this expression -
^[a-zA-Z0-9\(\),'@\-\.\s]{1,}$

The slash in the expression is to make a character to be treated as a literal instead of a special character

To handle a space, \s is used

Match: ABC, (44-4136), 'a@google.com'
Daivagna Nanavati replied to theiry henry on 01-Oct-10 02:58 PM
Hi

You can create the regex and use the match() method of regex in javasacript like following

<SCRIPT LANGUAGE="JavaScript"><!--
function demoMatchClick() {
  var re = new RegExp("^[a-zA-Z0-9 -()@,.]*$");
  var txt = dpcument.getElementById("txt").value;
  if (txt.match(re)) {
  alert("Successful match");
  } else {
  alert("No match");
  }
}

you can run it at your end and test it and play with it...by modifying it...

Thanks
undhad ashwin replied to theiry henry on 21-Oct-10 08:01 AM
<SCRIPT LANGUAGE="JavaScript">
function validateEmail(obj) {
  var re = new RegExp("^[a-zA-Z0-9 -()@,'.]*$");
  var txt = obj.value;
  if (txt.match(re)) {
  alert("Successful match");
  } else {
  alert("No match");
  }
return false;
}
</SCRIPT>

 <asp:TextBox ID="email" runat="server" onblur="return validateEmail(this);"></asp:TextBox>