|
-
Jun 11th, 2002, 05:08 AM
#1
Thread Starter
Fanatic Member
Strings in javascript
Hi,
I need some examples of string functions in javascript. My aim is to validate a date value to check that it is in the format that I want it to be in. I will need to an equivilent of vb split function or instr and mid.
Anyone got some examples for me?
-
Jun 11th, 2002, 05:43 AM
#2
Fanatic Member
there is a javascript split function too. Theres also substring and indexOf that maybe what you require.
Have a read of this. It shows all methods and functions associated with the js string object
http://www.w3schools.com/js/js_string.asp
-
Jun 11th, 2002, 07:43 AM
#3
Frenzied Member
You can also check my sig for links to the documentation on JavaScript, where you can find everything you need to know about the String object.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 11th, 2002, 07:57 AM
#4
Hyperactive Member
You can use regular expressions for patter matching
eg.
Code:
//lets check for dd/mm/yyyy
correct_date = "02/03/2002";
incorrect_date = "02/03/02";
if( correct_date.match(/^\d{2}\/\d{2}\/\d{4}$/))
{
alert("date matches");
}
if( incorrect_date.match(/^\d{2}\/\d{2}\/\d{4}$/))
{
alert("date matches");
}
the previous example uses this regular expression.
^\d{2}\/\d{2}\/\d{4}$
and the regular expression is enclosed by /regex/
^ = match the begiing of the string
\d = any numeric char
{n} = match n times the previous element
\/ = a literal /
$ = match the end of the string
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|