Email validation function cannot insert inside the cs file - javascript

I have a regex email validation function that i have take it from here .But the problem is when i insert it to my cs file then it shows me the errors.( it shows me lots of erors like unexpected / , ] expected,; expected )
Code
function ValidateEmail(email) {
var expr = /^([\w-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
return expr.test(email);
}
In here i have paste the screenshots also,

It's because you're trying to use # in JS but it's recognized as a Razor expression - you see that Razor colored it yellow? you need to escape it. e.g. use ## so Razor would understand you're not writing a Razor expression.

I think you want to use that regex in C# if yes try it like this:
[IdeOne Demo]
string email = "an.email#ahost.com";
string regex = #"^([\w-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex rgx = new Regex(regex);
Boolean result = rgx.IsMatch(email);

Related

javascript regex does not work properly with postal code

'^[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]{1}\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}[ -]*\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}\d{1}$'
the above regular expression accepts inputs like T3K2H3 or T3K-2H3 from .net form but when i run the validation through the javascript; it does not work.
var rxPostalCode = new RegExp('^[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]{1}\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}[ -]*\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}\d{1}$');
var postalCode = 't3k2h3';
var matchesPostalCode = rxPostalCode.exec(postalCode);
if (matchesPostalCode == null || postalCode != matchesPostalCode[0]) {
$scope.AccountInfoForm.PostalCode.$setValidity("pattern", false);
$scope.showLoading = false;
return false;
}
I believe that in javascript, you have to do // instead of ''
as follows:
/^[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]{1}\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}[ -]*\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}\d{1}$/
You might want to check the following link:
Validate email address in JavaScript?
You have two syntaxes to define a regexp object:
var rxPostalCode = /^[abceghj-np-tvxy]\d[abceghj-np-tv-z][ -]?\d[abceghj-np-tv-z]\d$/i;
or
var rxPostalCode = new RegExp('^[abceghj-np-tvxy]\\d[abceghj-np-tv-z][ -]?\\d[abceghj-np-tv-z]\\d$', 'i');
Note that with the second syntax you need to use double backslashes.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
"Do not forget to escape \ itself while using the RegExp("pattern") notation because \ is also an escape character in strings."
var rxPostalCode = new RegExp('^[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]{1}\\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}[ -]*\\d{1}[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]{1}\\d{1}$');
That should work, I tested it in Chrome's console.
Try the following pattern:
^[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d
[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz][ -]*\d
[AaBbCcEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz]\d
Remove the $ at the end and see if that solves your problem.
I also simplified things a bit, the \d{1} is the same as \d
I would also change the [ -]* to [ -]? unless you want to allow multiple spaces or dashes
I suspect what is happening is that the $ expect the end of the line or string, and JavaScript may not store the VAR properly. See if remove the $ solves it, or possibly keeping the $ and trim() the string.

Form Validation With Regex

I've written a function to validate if a password is valid. The only problem I'm having is figuring out why this pattern that I've written in JavaScript isn't evaluating to true when tested with a password such as: 'SteveRogers#256'. Is this an issue with the way I've declared the regex pattern?
PHP
function check_password($pass_word)
{
$pattern = "#.*^(?=.{8,15})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$#";
return (preg_match($pattern, $pass_word));
}
JavaScript
function check_password(pass_word) {
var pattern = new RegExp("#.*^(?=.{8,15})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$#");
return pattern.test(pass_word);
}
Remove regex delimiters in Javascript as new RegExp takes a String in the constructor. Correct Javascript code should be:
var pattern = new RegExp("^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?\\W).{8,15}$");

How to use inline regex modifier in VB.NET

I'm using jquery validate for client side email validation.
Of course I also have server side validation and want to use the same regex as jquery does to validate the input on the server side.
I found this regex in the source of jquery validate:
// http://docs.jquery.com/Plugins/Validation/Methods/email
email: function( value, element ) {
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value);
},
Note the /iat the end of the regex to make the whole thing case insensitive.
I have a complex site with c# libraries Ánd VB libraries.
In both libraries I need to implement this email validation.
In C# I'm using this code:
Regex RegexEmailAddress = new Regex(#"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
Note RegexOptions.IgnoreCase at the end.
However, In my VB code I need a string that hold the regex pattern.
Public Const MAIL_REGEX As String = "^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
So far I coudn't find any working regex adjustment to make this regex case insensitive.
I tried adding (?i) in front of the string but it's logged as invalid regex when using it on my website.
also add /i at the end of the pattern gives an invalid regex.
Update:
I tried another method with inline regex modifier I found in this SO question.
Case sensitive: ^[0-9]\s(lbs|kg|kgs)$
Case insensitive: (?i:^[0-9]\s(lbs|kg|kgs)$)
But it's also not working.
Here's the javascript error I get:
Uncaught SyntaxError: Invalid regular expression: /(?i:^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$)/: Invalid group
Update 2
I'm using RegularExpressionValidator
RegularExpressionValidator rxvalEmail = new RegularExpressionValidator();
rxvalEmail.ID = "rxvalEmail";
rxvalEmail.ValidationExpression = SomeHelperInVB.MAIL_REGEX;
rxvalEmail.ControlToValidate = "txtEmail";
So how can I make my regex case insensitive using a inline regex modifier? Of any other sollution to solve this?
I made a simple console application and by using (?i) it works just fine:
Module Module1
Public Const MAIL_REGEX As String = "^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
Public Const MAIL_REGEX_I As String = "(?i)^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$"
Sub Main()
Dim r_sensitive As New System.Text.RegularExpressions.Regex(MAIL_REGEX)
Dim r_insensitive As New System.Text.RegularExpressions.Regex(MAIL_REGEX_I)
' Returns true
Console.WriteLine("ok#ok.com: " + r_sensitive.IsMatch("ok#ok.com").ToString)
' Returns false
Console.WriteLine("NOT_ok#ok.com: " + r_sensitive.IsMatch("NOT_ok#ok.com").ToString)
' Returns true
Console.WriteLine("ok#ok.com: " + r_insensitive.IsMatch("ok#ok.com").ToString)
' Returns true
Console.WriteLine("NOT_ok#ok.com: " + r_insensitive.IsMatch("NOT_ok#ok.com").ToString)
Console.Read()
End Sub
End Module
Update:
OK, so you are using RegularExpressionValidator to do validation on both client and server. ..
Since the syntax is different between VB-RegEx and Javascript-Regex I'm not sure it's possible to do what you want. In VB you use (?i) in the beginning of the expression whereas in Javascript you need to add /i as a modifier when construction the expression (http://www.w3schools.com/jsref/jsref_obj_regexp.asp).
Maybe you need to use another expression, which doesn't require a "case-insensitive modifier". This one is from Expresso (http://www.ultrapico.com/expresso.htm):
([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})
Or, another option would be to replace [a-z] with [a-zA-Z] in your current expression.
Neither of the two expressions works when using Internationalized Domain Names, like "any.name#domännamn.se" (notice the "ä" in the domain name).
Some information that might could help others:
I found out why the regex modifiers aren't working for RegularExpressionValidator when debugging the client side code used for validation.
The code below shows how client validation for regex is done using RegularExpressionValidator control:
function RegularExpressionValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
var rx = new RegExp(val.validationexpression); // Error: Invalid regular expression:....
var matches = rx.exec(value);
return (matches != null && value == matches[0]);
}
new RegExp("pattern/i") will be formatted as: /pattern/i/
and that's indeed no valid regex. The valid regex would be: /pattern/i
=> Conclusion: Modifiers can't work using RegularExpressionValidator. I'll probably write use CustomValidator control instead with custom server and client side code.
Another option would be to replace [a-z] with [a-zA-Z] in the used regex

How to validate this string not to contain any special characters in Javascript?

I have a dynamic string like this which may look like:
"69.43.202.97" OR "ngs.pradhi.com"
I want to validate these string contains only numbers, english alphabets and "." . I want to validate this in front end using java script. I thought of using regular expression like this:
function validatePath() {
var path = document.getElementById('server_path').value;
path.match([a-z][0-9]) //or something like this
}
If the path is invalid despite of displaying the alert box I just want to show the error below the text field as soon as the user fills the server path. How can I do that?
My full javascript function looks like this:
function validatePath() {
var path = document.getElementById('server_path').value;
if (path.search(":") == -1){
alert("Invalid server path");
}
else{
var host_name = path.split(":")[0]
if host_name.match("^[a-zA-Z0-9.]*$")) {}
}
}
try path.match("^[a-zA-Z0-9.]*$")
EDIT:
var regex = new RegExp("^[a-zA-Z0-9.]*$");
if(regex.test(host_name)){}
you can use /^[a-zA-Z0-9.]*$/.test(path) which will return true or false
To be different, replace method:
if(path.replace(/^[a-z\d.]*$/i,"")=="")
You can do the check (including port presence) with a regex like this:
^[a-zA-Z0-9\.]+:[0-9]+$
(Note the + instead of * to account for empty path or port (they are not allowed).)
If you are using HTML5, consider the newly introduced "pattern" and "required" attributes, which can posdibly save you some JS code.
See this short demo for an illustration of both technics.
Some links you might find useful:
Regular Expressions
The HTML5 "pattern" attribute
The HTML5 "required" attribute

Regular Expression to validate email: illegal character

Doing form validation using Jquery without plugins, they're easy enough to use. Trying to teach myself regular expressions and at a wall.
var email = $('#email').val();
// Validate email address
// Regular expression to match email address:
var emailReg = \S+#\S+;
if(email.match(emailReg)) {
// Pass
}
else {
// Fail
$('#email').css("background","yellow");
var counter2 = setTimeout("$('#email').css('background','white')", 3000);
return false;
}
I know it's the worlds simplest regular expression, just trying to get functionality and I'll get more sophisticated later.
Keep getting SyntaxError: illegal character \S (here) +#S+
Don't understand why. Have searched this site and tried dozens always with console errors.
Add / around it.
var emailReg = /\S+#\S+/;
^ ^
You need to place your regex in forwardslashes like so:
var emailReg = /\S+#\S+/;
This way it knows it's a regex object, instead of just random operators put together
You could also do:
var emailReg = new RegExp("\S+#\S+");
This method is useful if you aren't just writing a static regex (eg. getting the regex from user input)
Regular expressions are enclosed in forward slashes in js. Try
var emailReg = /\S+#\S+/;

Categories

Resources