Developing a Regex pattern for an email [duplicate] - javascript

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 9 years ago.
I have no experience with regular expressions in java script, but I need to derive a pattern for
FMLast1234#ung.edu. There only needs to be a pattern for FMLast1234 because #ung.edu needs to remain the same. I am not sure if I just do this \b[a-z][a-z][a-z][0-9] or what.
Does there need to be a range for each character in the pattern? I need to check for variations of the pattern FMLast1234 not just a random assortment of characters and numbers.

/[a-zA-Z0-9]#ung.edu/.test("123#ung.edu") or
if(emailString.split('#')[1] === "ung.edu")
Edit : As per plalx comment here is my answer
/^\w+#ung.edu$/.test("aaa123#ung.edu")

Related

Regex. Escape group? [duplicate]

This question already has answers here:
Is there a RegExp.escape function in JavaScript?
(18 answers)
Closed 5 years ago.
Is there any way to make something.+()[]* matching literally 'something.+()[]*'? I'm using regex builder so manual escaping is not allowed. Sure, i can add hardcoded checks if (char === '+') return '\+' but i'm looking for native solution or better way
UPD
I'm sorry. I forgot to add that matching should be in given order with moving forward but not back. So [+.] will not fit my requirements because it will match both +. and .+. I need only first case (In definition order)
You don't need to escape them if within square brackets.. I just tested and works for me, but maybe not what you are looking for?
something[.+()[]]

Restrict duplicate words in email regular expression javascript/jquery [duplicate]

This question already has answers here:
How can I validate an email address in JavaScript?
(79 answers)
Closed 6 years ago.
I want to restrict duplicate words in an email using regex.
Currently I am using below regex that also restrict 2 consecutive dots (ex: a#gmail..com)
regexp: /A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*##(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z][{a-z},0-9](?:[a-z0-9-]*[a-z0-9]){1-2}?)$/i,
Now I want to also restrict duplicate words in email for example :-
abc.xyz#gmail.com.com
It should not accepted second .com .
What about:
email="hello.world.world";
email=email.split(".");
fail = email.some((ae,ai)=>email.some((be,bi)=>bi==ai?false:ae==be));
//loop trough all pairs, if they are at the same index skip ( we dont want to check email[0]==email[0]), else compare, if same fail.
if(fail){alert("Wrong email");}

Ignoring line breaks in Javascript regex [duplicate]

This question already has answers here:
JavaScript regex multiline text between two tags
(5 answers)
Closed 4 years ago.
Even if I use the m flag, javascript regex seems to isolate regex matching by lines.
Example:
"if\nend".match(/if(.*?)end/m)
=> null
I want this to match. How do I get around this?
You actually want s (a.k.a. "dotall"), not m, but javascript doesn't support that. A workaround:
"if\nend".match(/if([\s\S]*?)end/)

Text between two dollar signs JavaScript Regex [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 6 years ago.
I'm trying to use RegEx to select all strings between two dollar signs.
text = text.replace(/\$.*\$/g, "meow");
I'm trying to turn all text between two dollar signs into "meow" (placeholder).
EDIT:
Original question changed because the solution was too localized, but the accepted answer is useful information.
That's pretty close to what you want, but it will fail if you have multiple pairs of $text$ in your string. If you make your .* repeater lazy, it will fix that. E.g.,
text = text.replace(/\$.*?\$/g, "meow");
I see one problem: if you have more than one "template" like
aasdasdsadsdsa $a$ dasdasdsd $b$ asdasdasdsa
your regular expression will consider '$a$ dasdasdsd $b$' as a text between two dolar signals. you can use a less specific regular expression like
/\$[^$]*\$/g
to consider two strings in this example

regular expression for validating email addresses [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What is the best regular expression for validating email addresses?
I have the following expression
**replacePattern3 = /(\w+#[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
replacedText = replacedText.replace(replacePattern3, '$1');**
but it doesn't validate email if the email in this form a.b#alexmed.com it only validate email in form a#alexmed.com
i need another expression to validate the form a.b#alexmed.com
I think \w+ is the same as [a-zA-Z0-9], so it doesn't like the dot. I'm not good at this, but try
**replacePattern3 = /(\[a-zA-Z0-9\.]+#[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
You also might want to add a few more symbols to most places, because domain names can have numbers and certain symbols in them.

Categories

Resources