Regular Expressions - Match An Email String That Ends Exactly With ".com"?

Jan 17, 2011

I am trying to match an email string that ends exactly with ".com". Here's what I have

var email = window.prompt("Enter your email", "");
var email_match = /[a-zA-Z1-9-_.]{3,}@[a-zA-Z]{3,}.(com)/
if (email_match.test(email))


the (com) also matches commm for some odd reason. What must I change in the code so that only emails ending with .com is valid?

View 3 Replies


Build A Regular Expressions For Email

Feb 3, 2010

Code JavaScript:
function regExpression(stringValue) {
if (stringValue === null || stringValue.length === 0) {
alert("No string was entered"); }
else if (stringValue.match(/^[_.-a-z0-9]+@[_.-a-z]+.[a-z]{2,4}$/i) != null)
alert("This is a valid email.");
else {
alert("The string is not a valid email."); }

The problem is that: Code: works. The 123 in the provider shouldn't be allowed, but it is. I'm trying to build a regular expressions for email.

View 2 Replies View Related

Regular Expressions - Detect Letters In String?

Mar 2, 2011

I'm trying to make a script which will check if the string which the user sent from a form contains ONLY letters. The problem is if the user entered something like this "25 years old" it allow that to be submitted. It only blocks submissions of the form if the user submits NO letters like this "12345". I want it to block submissions if at least one character isn't a letter. Here's my code:

var message = document.myform.formtest.value;
var allowed = /[A-z+]/;
if(!allowed.test(message)) {
alert("The field only allows letters (a-z).");
return false;

View 9 Replies View Related

Regular Expressions - User Input A String Or Something And Have To Validate It ?

Apr 23, 2010

I'm kind of confused about how to use regular expressions. I'm trying to have the user input a string or something and i have to validate it. The example im suppose to do has numbers only and must have 9 digits.

Here's what i have:



View 2 Replies View Related

Adding Specific Text In A String Using Regular Expressions?

Feb 2, 2010

I have some long html text like this:

HTML Code:
some text [URL].. continue of the text How can I add some content before and after the matching statement. I meant for example how can I change the above text into:
HTML Code:
some text <a href=""></a> continue of the text

View 1 Replies View Related

What Regular Expression Will Match ANY String That Has 10 Digits In It

Jan 13, 2009

What regular expression will match ANY string that has 10 digits in it?

View 24 Replies View Related

Match Entire String (regular Expression & Javascript)

Jul 23, 2005

I'm trying to perform a very simple validation of user input. I
want to verify that the user entered a six-digit string consisting
entirely of numbers. So anything from 000000 to 999999 is considered
valid. The problem that I'm having is getting the validation to work on
the entire string. In other words, 000000 is okay but 000000000000 is
also returning as a match. Here's a quick code block...I have something
along these lines....

<INPUT name="txtNumberField" type="text" id="txtNumberField">
<INPUT onClick="fnTestNumberField()" id=Button1 type=button value="Test
Number!" name=btnTest>
<script language=javascript>
function fnTestNumberField()
var sNumberValue = document.getElementById("txtNumberField").value;

if (sNumberValue.match(/A[0-9]{6}z/))
} else {
alert("no match");

That is failing when I enter 123456 into the textbox. Why, though? I
know I can replace...

if (sNumberValue.match(/A[0-9]{6}z/))

....with something like...

if (sNumberValue.length == 6 && sNumberValue.match(/[0-9]{6}/))

....or I could assign a maxlength to the input box, of course. The thing
is, I really want to know WHY the regular expression isn't responding
as I'd expect. Is there a syntax error somewhere in the code?

View 2 Replies View Related

Regular Expressions Challenge

Jul 23, 2005

Coding patterns for regular expressions is completely unintuitive, as far
as I can see. I have been trying to write script that produces an array
of attribute components within an HTML element.

Consider the example of the HTML element TABLE with the following
attributes producing sufficient complexity within the element:

<table id="machines" class="noborders inred"
style="margin:2em 4em;background-color:#ddd;">

Note that the HTML was created as a string in code, and thus there are NO
newlines ('
') in the string, as if a file was newlines are
not an issue. The only whitespace is the space character ' ' itself,
required to delimit the element components.

I want to write an RE containing paranthesized substring matching that
neatly orders attribute components. The resulting array, after the
execution of the string .match() method upon the example, should look as

attrs = [ "id", "machines", "class", "noborders inred", "style",
"margin:2em 4em;background-color:#ddd;" ]

I can then march down the array (in steps of 2) setting attributes
(name=value) to the element using standard DOM interface methods, right?

In approaching the writing of the RE, I have to take into account the
characters permitted to form the attribute name and the attribute value.

I assume a start to the RE pattern as:

<attribute name>=<attribute value>

I then try to find the right RE pattern for <attribute name>, keeping in
mind what the legal characters are for attribute names according to the
HTML standard ("recommendation"):


I believe this patterns conforms to the standard for attribute values:


That pattern tries to be more exclusive than inclusive, although I think
just about every character on the planet, including a newline, is
acceptable in an attribute value, at least the kind one might see in an
HTML document. Code:

View 7 Replies View Related

Regular Expressions For Username

May 24, 2007

I am trying to construct a reg exp for a field which can accept username as
(username) or ( etc).

username should allowed alphanumeric values also it should accept -,_,.
it should not allowed @ twice

View 2 Replies View Related

Simple Regular Expressions

Jul 5, 2004

I'm having a problem making the regular expression for U.S. zip code verification work.
the regular expression: /(^d{5}$)|(^d{5}-d{4}$)/

My code is below. No matter what I type in, it asks me to correct my zip code. Any suggestions? Code:

View 2 Replies View Related

Regular Expressions In JavaScript

Jun 3, 2001

I am trying to use regular expressions within JavaScript for the picture upload component of a shopping cart. I still can't seem to get my mind around them.

I have a page with a working file upload. When you click on browse and then select your file, the file name is also returned to the second field, the picture name field. The problem is that the entire string is returned - 'G:CatalogMyPicturessomepic.jpg' instead of 'somepic.jpg'.

I know this can be pulled out with regular expressions, everything from the right until it hits a / or I included the script and a couple of links. Code:

View 3 Replies View Related

Regular Expressions To Perform Validations?

May 6, 2010

know there is a similar post on here but it didn't really give me any actual help on this topic:It seems that I have the correct regular expressions in this however it doesn't want to follow my freaking instructions can you guys maybe show me where I'm going wrong and give me a short source code on how to rectify it. Code is below:

function validate(theForm)
var falseCounter = 0;


View 7 Replies View Related

Form Validation Using Regular Expressions?

May 3, 2010

I'm trying to validate the form, but each time I try to do so, all fields return invalid. I've tested my regular expressions with various online testers and they seem to work fine, am I perhaps using it in the wrong way? Or maybe a problem with my functions?


View 4 Replies View Related

Form Verification Using Regular Expressions?

Mar 4, 2011

i'm trying to use a regular expression to verify an order. I basically don't want any decimals or negative numbers allowed. I believe I have any digit 0-9 one or more times and negating decimals. but for some reason it allows decimals and letters. also is it correct to put return true or can i just leave it blank?

var varifyThree = /^\d*[^\.]$/;
var productThree = document.getElementById('prod3').value;
if (productThree==null || productThree=="" || varifyThree.test(productThree)) {
return true;


View 8 Replies View Related

Form Verification Using Regular Expressions

Mar 7, 2011

I keep getting an error that says item is null. I'm a little lost because once I got my regExp to start working this actually worked for a little bit. When I came back I was getting an error.

var creditExp = /^([345])(\d{3})\-?(\d{4})\-?(\d{4})\-?(\d{4})$/;
var creditNumber = document.getElementById("creditnum").value;
var item = creditExp.exec(creditNumber);
document.getElementById("creditnum").value = item[1] + item[2] + "-" + item[3] + "-" + item[4] + "-" + item[5];
if (item[1] == 4 && document.getElementById("card1").checked == true) {
return true;
if (item[1] == 5 && document.getElementById("card2").checked == true) {
return true;
if (item[1] == 3 && document.getElementById("card3").checked == true) {
return true;
} else {
alert("You must enter a valid credit card number.");
return false;
var billingName = document.getElementById('creditname').value;
if (billingName == null || billingName == "") {
alert("You must enter your first name as printed on your credit card!");
return false;

View 1 Replies View Related

Macintosh MSIE And Regular Expressions

Dec 27, 2005

Here's what used up the last couple of hours of my time.

The Mac version of MSIE will not load a script that has this in it:

theItem.elm.value = theItem.elm.value.replace(/^s*(.*?)s*$/, "$1");
Now I had other regular expressions in the script done this way, but in this one case I had to use the object constructor method.

It will won't work in this browser, but now at least the script loads and other functions in the same file work.

I have a solution so basically I'm looking for some insight into this if anyone has it. What is it about this particular expression that upsets Mac MSIE?

View 1 Replies View Related

Regular Expressions Crashes My Browser / Why Is So?

Dec 20, 2010

Explain to me why this doesn't work? code... All it does is crashes my browser.

View 1 Replies View Related

Validate A Date By Using Regular Expressions?

Oct 4, 2011

I am trying to validate a date by using regular expressions.I have parts working, such as only accepts numbers, but I cannot get the range correct. On the "mm" field, I am getting errors.

alert("Please insert your birth month");
return false;}


View 1 Replies View Related

JQuery :: Replacing Content With Regular Expressions?

Feb 21, 2011

I have a string content which include the content "[some number]". I wanted to replace the inner number which is inside the square bracket with jQuery regular expressions. the number inside the brackets are always variables.

View 3 Replies View Related

Regular Expressions For Phone And Postal Code?

Mar 26, 2009

provide regular expressions for Phone and Postal Code for the specified formats only? My phone # format is 416-642-3481(3digits-3digits-4digits). Please make sure I need a regular expression to satisfy only this format 416-111-1111. I don’t need any brackets, spaces, and country code. My Postal Code format is M4A-2S3 or m4a-2s3. Please make sure I need a regular expression to satisfy only these 2 formats M4A-2S3 or m4a-2s3. I don’t need any brackets, spaces, and country code.

View 7 Replies View Related

Grabbing An Entire Tag And Contents With Regular Expressions

Dec 6, 2004

I want to create a function with Javascript regular expressions that will grab the entire contents of a custom tag and place that into a string. Including the tag that I am grabbing.

This is what I think the regular expression should look like:


Whats the best way to use Javascript to place the results of my Regular Expression shown above into a string.

For example:

if myString = "bla bla bla <myTag>some more text</myTag>" then I need a command that will use the regular expression to put "<myTag>some more text</myTag>" into another string var.

I think I need to use the RegExp command in Javascript but I am unsure.

View 1 Replies View Related

JQuery :: Validation Plugin - Regular Expressions Or Condition?

Mar 7, 2011

I´ve problem with Validation plugin... I´ve one select like this..


Next problem is with the right phone number format.. I have a PHP regular expression, but I don´t know how to insert this regExp into JS.

View 7 Replies View Related

Regular Expressions Exec Method - Returning Array?

Sep 8, 2010

var toSearch = "I Wish This Worked. What Is The Issue?";
var pattern = /is/gi;
result = pattern.exec(toSearch);
alert(result.length); Shouldn't this be 4, not 1?
/*while((result = pattern.exec(toSearch)) != null)
alert(result[0] );*/
The commented out code works to access all instances of 'is'. But what's the point of returning an array if you're only going to use one index(0)? You'd have to manually code to get a full array of the returns, doesn't that defeat the purpose?

View 3 Replies View Related

Regular Expressions - Input Validation 6 Digit Umber Only

Oct 15, 2009

i am wanting to validate an input field to only validate if 6 numbers are entered

I am reading Simply JS book and can't seem to find anything about that.

View 2 Replies View Related

Regalur Expressions - Operator On Words And Phrases Without Adding Terms To The Match Array?

Feb 3, 2011

I have a set of regular expressions that make heavy use of the | operator on sections that I do not really need to extract a match from. For example:

var regexp = /([A-Z][A-Za-z]+) (jumps( high)?|leaps|bounds) over ([A-Z][A-Za-z]+) and (grabs|snags|gets) (a|an|the) (apple|orange|pear|grapes)/

The important part for extracting from the match array after using regexp.exec() are the names (the ([A-Z][A-Za-z]+) parts), I don't care which of the other things are matched. The problem is that using the | operator seems to necessitate using the () and adding a term to the match. This makes it difficult to know which term in the array will be the names, especially after editing the middle.So I'd like to be able to use the | operator on words and phrases without adding terms to the match array.

View 2 Replies View Related

Regular Espressions And .match()

Jan 21, 2003

I have a regular expression called mCheck and a variable called usrVal which contains &#391;/20/41/11/22' I then use the usrVal.match(mCheck) so the code looks like the following

var mCheck = /^[0-9][0-9]/;
usrVal = &#390;' + usrVal;

Now, I was under the impression that if there wasn't a match then the match method would return boolean 'False'. However it is returning 'null' instead... I have used this exact same check on other pages before and it returned false just fine....

View 9 Replies View Related

Copyrights 2005-15, All rights reserved