Regular Expression Allow Alpha Characters Only?

Jan 27, 2010

This is my first serious attempt at using a regular expression.My first name field should allow alpha characters only [A-Za-z], but it seems to be testing for the presence of 1 alpha character. If one is found in the string then anything else is allowed.Bob returns valid which is what I need.Bob1 returns valid but should NOT be valid..1 returns valid not valid which is what I need.My code.

function isValidFirstName(p1_firstName) {
//http://www.javascriptkit.com/jsref/regexp.shtml
var re = new RegExp("[A-Za-z]");

[code]....

View 6 Replies


ADVERTISEMENT

Regular Expression And Match Anything Between Two Characters

Sep 19, 2009

I have the following code:

var str = "/dev/filler/test0/";
var patt = new RegExp("/test0/$");
var result = patt.exec(str);
document.write(result);
which returns: /test0/

in the var patt line I would like to replace the hardcoded test0 string with an expression that matches any characters between the two forward slashes. I have tried with little success.

View 3 Replies View Related

Escape Regular Expression's Special Characters?

Jun 14, 2010

am in need of escaping the regular expression special characters like '/', '.', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\'.I have try with this by the following javascript but i can not achieve that.

RegExp.escape=function(str)
{
if (!arguments.callee.sRE) {

[code]....

View 9 Replies View Related

Regular Expression :: String Must Be 6 Characters Long And A-Z, A-z And 0-9

Apr 26, 2007

String must be minimum 6 charcters long and can only contain A-Z, a-z and 0-9 ....

View 2 Replies View Related

Regular Expression Methods, Problem With Escape Characters

Sep 13, 2006

Attempting to use javascript's regular expression methods to match a
particular lab number and building which would then be copied to a pair
of textfields, I found that general matching characters needing a
backslash were not recoginized. The following adapted code that finds
a two-button radio selection shows my problem:

function labstat(){
for (i=1; i<3; i++){
if(document.tester.rm_mod[i-1].checked){
var lb = document.tester.elements["lab"+(i)].value;//either
214 or 215*
var bld = document.tester.bldg.value;
if(/*/.test(lb)){ //error:Undetermined comment
// if(/*/.test(lb)){ //error:Syntax error
// if(/5/.test(lb)){ //works to match only 215*
// if(/5*/.test(lb)){ //true for all
// if(/ddd/.test(lb)){ //false for all
document.tester.room1.value = lb;
document.tester.bldg1.value = bld;
}
}
}

It appears that the escaped characters are not recognized, whichever
form of the method is used, i.e var re = /*/; // or = new
RegExp("*");
if(re.test(lb)){
--------
With the --.match(__) method I have the same problem.

View 9 Replies View Related

Regular Expression - Enter A String That Is 2 - 20 Characters Long And Only Has Letters Doesn't Work

Jun 28, 2010

I wanted to try creating a basic expression first. I want someone to enter a string that is 2 - 20 characters long and only has letters. This is what I use so far, and it doesn't work, nothing happens at all when I run it.

Code:
// Check for a valid name.
var namePattern = new RegExp("/^[a-zA-Z]{2,20}$/");
if (namePattern.test(name))
{
window.alert("Invalid");
}

name comes from a input box I display on screen. Also, I would like to update the expression so that there can be one space in the string, but it cannot be at the beginning or end. So this string is like a persons name. Bob is OK, Bob Smith is also OK. Edit: Actually, it is doing something but its always coming back invalid.

View 9 Replies View Related

Validation Form To Only Allow Alpha Characters And Space

Apr 18, 2011

With the code I had to acknowledge nothing had been inserted,(that is, still spaces, it was working. When I added the code to only accept alpha chars etc., I inserted numbers, nothing worked, with no error message. Would you, or can I send the whole code through for the form. I noticed that the form tags had been changed so I altered them as well according to your message.

View 7 Replies View Related

?: In Regular Expression

Feb 21, 2006

I have seen lot of reg. expession with ?:
For dummy eg
(((XXX)ddd)ff)

The above expression is modified as
(?:(?:(XXX)ddd)ff)

Although both the above expr. gives same result. (RegExp.match() gives
same o/p), most of the places , i have seen second option.

Yes, but different matches r shown (using RegExp.exec())

Is the second expr. most efficient or in particular scenarios?

Any comments???

View 5 Replies View Related

Regular Expression Problems

Jun 28, 2006

At the moment my code is like:

function telValid(inString) {
var regexp = /^[0-9 +()]+$/;
return (inString.match(regexp,''));
}

which is use to validate phone numbers (UK at the moment)

this works ok, but wont allow - (Dashes) which i need..

tried doing:

function telValid(inString) {
var regexp = /^[0-9 +-()]+$/;
return (inString.match(regexp,''));
}

View 2 Replies View Related

Regular Expression Replace.

Jan 20, 2007

I am finding it difficult to find a regular expression for following situation(replace)

a b c d = a,b,c d
a b c = a,b c

View 8 Replies View Related

Regular Expression To Get The File Name From A URL?

Feb 5, 2009

regular express to get the file name from a URL?

It has to be flexible in that the extension can be either 4, 5, or 6 chars (.php, .html, .shtml for example) and needs to cater for and whether querystring parameters exist too.

So, both

[URL]

and

[URL]

The regex should return newthread for both.

View 4 Replies View Related

Get Innerhtm Value Using Regular Expression?

Nov 13, 2009

I.E.:

---------------------------
Windows Internet Explorer
---------------------------
<EMBED src=http://www.youtube.com/v/JTmM3jut05Q&hl=en&fs=1& width=500 height=200 type=application/x-shockwave-flash allowfullscreen="true" allowscriptaccess="always"></EMBED>

how can i get "src" value in above code using regular expression?

<object width="500" height="200"><param name="movie" value="http://www.youtube.com/v/JTmM3jut05Q&hl=en&fs=1&"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/JTmM3jut05Q&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="200"></object>

how can i get "src" value in above code using regular expression?

View 6 Replies View Related

Regular Expression For Substring?

Jul 7, 2010

what will be the regular expression for this line:

Code JavaScript:
var id = $(this).attr("href").substring( $(this).attr("href").lastIndexOf('#'), $(this).attr("href").length);

Basically it gets the string after # in href attribute of clicked anchor tag.

View 3 Replies View Related

Regular Expression For A Date?

Aug 26, 2010

I have this expression:

/(19|20)dd/)[- /.](0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])

to detect if my date:

2010-12-15

is valid. It's not working. What do I have wrong?

View 6 Replies View Related

Explorer 5.01 Regular Expression Bug

Dec 30, 2004

When Internet Explorer 5.01 for Windows hits the regular expression:

/(?=<)|>/

it complains about an unexpected quantifier. In fact, it seems to complain whenever I use a lookahead expression. Is there any way around this?

View 2 Replies View Related

How To Build A Regular Expression On Runtime?

Jul 23, 2005

does anyone know how I can build a regular expression e.g. for the
string.search() function on runtime, depending on the content of
variables? Should be something like this:

var strkey = "something";
var str = "Somethin like this";

if( str.search( / + strkey + / ) > -1 )
{
...
}

View 9 Replies View Related

Comma Delimited Regular Expression

Dec 7, 2006

I need a regular expression that will validate a double quote comma
delimited list where the odd entries are numeric and the even are
alphabetical. Each pair must also be on a separate line. For example:

"1","Peter"
"2","Paul"
"3","Mary"

I've used the following expression to validate comma delimited lists, but
without the double quotes, numeric/alpha pairing and line return
restriction.

^([A-Za-z0-9]?)+([,]s?([A-Za-z0-9]?)+)*$

View 1 Replies View Related

Regular Expression To Match Any Spaces

Oct 9, 2007

Normally I can write regular expressions decently well but for some
reason I am having trouble getting this to work. I am validating form
data and need to throw an error if there are ANY spaces in the field.
abc123 is fine, abc 123 is not. Any character is fine, just not a
space.

View 2 Replies View Related

Regular Expression To Exclude Lines?

Jul 20, 2005

All I'm trying to do is delete the lines which don't contain a particular
string. Actually a filter to edit a log file. I can find and replace a thing
with null, but can't figure out how to find the lines which do not contain
the thing.

Going further, I want to generalize and use a JavaScript variable containing
the decision string, but first I need to worry about the not-within-a-line
problem.

View 26 Replies View Related

JQuery :: Regular Expression Validation?

Aug 7, 2009

I would like to validate a textbox that numbers cannot be entered into the text input, how do i do this??? With regular expression??

View 8 Replies View Related

JQuery :: Using A Regular Expression As A Selector?

Oct 15, 2010

Does jQuery support a regular expression as a selector? eg: so I can get every element with a id beginning with "test"

View 2 Replies View Related

Parse A CSV Line With A Regular Expression?

Mar 19, 2008

I've got a somewhat cumbersome function that looks like this.

Code:

parseCSVLine = function (line)
{
var tmp = [];
var inQuote = false;

[Code]....

View 4 Replies View Related

Regular Expression For US Phone Numbers?

Apr 30, 2009

Here is the form in question: spraytechDOTcom/download_form.asp I am so close to getting this to work the way that I want, but here is what I am having an issue with: I cannot seem to make it look for the 12 digits that are in the phone numbers that we are going to collect. Ex. 800-123-4567

It doesn't have require 12 characters if there is another way to get the number to validate looking like the example above. Here is my regular expression that I am struggling with:

var re = /[^d-]$/ It seems to block any letters, but it will accept only 1 number. I would really like it to make sure that the phone number is only entered like this: 800-123-4567.

I have looked for days trying to figure this out and have only gotten close.

View 7 Replies View Related

Regular Expression To Validate Township

Mar 31, 2009

I'm trying to validate data in a textbox for township (usually written as 12N or 23S for Township 12 North or Township 23 South). In Utah the townships range from 01N to 15N, and 01S to 44S. The expression "/[0-9][0-4][ns]/i" will allow 01n (or s) through 94n (or s). If I change it to "/[0-4][0-4][ns]/i" to limit it to 44n (or s), I then am not allowing for 05, 06, 07, 08, and 09. I hope the above is not too confusing. I'm just starting to work with regular expressions.

View 2 Replies View Related

Perform A Regular Expression On A String?

Sep 8, 2009

I would like to perform a regular expression on a string and if TRUE do something.

I have huge amounts of knowledge doing this in PHP but trying out javascript.

View 1 Replies View Related

Regular Expression For URL With Optional Domain?

Feb 4, 2010

I am creating a regular expression for a URL where the domain name (i.e. .com|.edu etc) is optional. That is both http://xyz and http://xyz.com should be valid. If <.> is present then com|edu|.. will be there; but if <.> is absent then com|edu|.. will not be there. Also there can be any number of <.>, but every <.> will be followed by characters. So in other words the string can't end with <.>, it should only end with [a-zA-Z0-9]. So far I have created the following part -

var url=document.myform.addr.value;
var str="^(http|https)://(([a-zA-Z0-9.-]+)*[a-zA-Z0-9-]+.(com|edu|gov|[a-zA-Z]{2})|[a-zA-Z0-9]+$)";
var regEx = new RegExp(str);

[Code]....

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved