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!

arguments 1

Status
Not open for further replies.

g8kpr

Programmer
Feb 17, 2003
7
0
0
US
I would like to know how to take in an argument (string) and convert int into an array of 20 characters, either using the following function heading, or something that you might suggest:

<script language=javascript>
<!--
function MyClientValidation(source, arguments){

var strValue = arguments.Value

//In here is where I would like to do the string conversion

}
-->
</script>

Can anyone help?
 

when you say &quot;...and convert int into an array of 20 characters...&quot;, does that means the array will consist of 20 parts, as in array[0],...array[19]?

will the value passed to this function always be the same length, presumably 20?

- g
 
Yes, the length of the array will always be 20. What I'm trying to do is read in an input from the user (using a text box) and checking to see if the input conforms to a particular pattern. If there is a better way to do this, I'm all ears. By the way, I'm using the .NET environment.

- thanks
 
what's the pattern you want to compare it to?
=========================================================
if (!succeed) try();
-jeff
 
The pattern is a combination of numbers and a &quot;.&quot; like:

if n = number from 1 to n then this would be valid
n.n.n (ie - 2.435.32 or 245.345.2 etc...)

I figured if I could create a function to break the &quot;string&quot; down to an array, then I could check to make sure that all entered information was either a digit or a &quot;.&quot;
 
you can use split! :)

say your string is

var str = &quot;214.123 32145.2123 123.321654&quot;

you can use split to have it in an array :

var strArray = str.split(&quot; &quot;); // notice I give a space as an argument here

and then strArray is just like a normal array with all your numbers in them.

Is this what you are looking for? Gary Haran
 
or use a regex:

function testString(s) {
var p = /^[\d\.]+$/gi;
return p.test(s);
}

call it like so:
<form>
<input name=&quot;myString&quot;/>
<input type=&quot;button&quot; onclick=&quot;alert(testString(this.form.myString.value));&quot;/>
</form>
=========================================================
if (!succeed) try();
-jeff
 
Thanks for all the help folks, I got it to work.

- jemminger - if you have time, can you explain to me what the /^[\d\.]+$/gi stands for.

Thanks
 
it's called a &quot;regular expression&quot;, or regex for short.

here's what the various symbols mean:
Code:
/     regex delimiter
^     beginning of line
[]    encloses a class or group of characters
\d    any digit 0-9
\.    a literal period/dot
+     one or more of the previous expression
$     end of line
g     make the expression global
i     make the expression case-insensitive
=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top