Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data validation 2

Status
Not open for further replies.

r0nke

MIS
Jul 17, 2003
60
0
0
US
Hi folks,

Please, how do i validate that the first two characters in a string are letters and the next 5 are numbers?

Like so: xx12345

Dont care about any characters after the first seven.

Regex or anything will do.

Many thanks

 
you can do this with javascript
function valMyField()
{
var field1 = document.forms[0].whateverField.value;
var objRegExp = /(^\D{2}\d{5}$)/;

if(!objRegExp.test(field1))
{
alert("Please Enter a Valid Field!");
return false;
}
return true;
}

<input type="text" name="whateverField" ... onChange="return valMyField();">


hope it helps

 
What if it doesn't come from a browser? impoted from a file or cfhttp etc... javascript isn't going to help him there. that's a big assumption...

Code:
<cfset x = "ab55133billybob788">
<cfif reFind("^[A-Za-z]{2}[0-9]{5}",x)>
	string ok
<cfelse>
	String not ok
</cfif>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
your regex is also a little off

/D means non DIGIT (0-9) 'x%12345' would pass the test.

you also added $ to the end so it can ONLY be 7 chars long, r0nke eluded it could be longer but didn't care about what followed the first 7.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
TruthInSatire,

You are right, what you posted was exactly what I needed.

FALCONSEYE,

Thank you for giving it a shot.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top