SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    asdasdsad
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool plz help a noob :)

    i need to transform this function to javascript
    Code:
    <SCRIPT language=VBscript>
    	function tt(str)
    		tt = trim(str)
    	end function
    	
    	function IsD(str)
    		for i = 1 to len(str) 
    			if Asc(mid(str,i,1))<48 or Asc(mid(str,i,1))>57 then
    				checkD = false
    				exit function
    			end if
    		next
    		checkD = true
    	end function
    	
    	function IsDC(str)
    		for i = 1 to len(str)
    			dd = Asc(mid(str,i,1))
    			if dd<48 or (dd>57 and dd<65) or (dd>90 and dd<97) or dd>122 then
    				IsDC = false
    				exit function
    			end if
    		next
    		IsDC = true
    	end function
    </SCRIPT>
    plz if someone can do it, i would be very happy

    thx

  2. #2
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript does not have a trim function like in vbscript. use the following function to remove the leading and trailing blank spaces from the string:

    function alltrim(s)
    {
    // Returns string with leading and trailing blanks removed.

    // Is s empty?
    if (isEmpty(s))
    return "";
    var i, n;

    // First find position of first nonblank character in string
    for (i = 0; s.charAt(i) == ' ' && i <= s.length;i++);

    // Search from end of string, find position of last nonblank character in string
    for (n = s.length; s.charAt(n-1) == ' ' && n >= 0;n--);

    return s.substring(i,n);
    }

    Now your tt function

    function tt(str){
    return alltrim(str);
    }

    Now IsD function

    function IsD(str){
    var blnCheckD = false;
    var strText = new String(alltrim(str));
    if(strText != ''){
    for(var i=0; i<strText.length; i++){
    if(strText.charCodeAt(i)< 48 || strText.charCodeAt(i) > 57){
    blnCheckD = true;
    break;
    }
    }
    }

    return blnCheckD
    }

    Now IsDC function

    function IsDC(str){
    var blnCheckD = true;
    var strText = new String(alltrim(str));
    if(strText != ''){
    for(var i=0; i<strText.length; i++){
    cText = strText.charCodeAt(i);
    if(cText < 48 || (cText > 57 && cText < 65) || (cText > 90 || cText < 97) || cText > 122){
    blnCheckD = false;
    break;
    }
    }
    }

    return blnCheckD;
    }


    I have not tested the conversion, check it and if you get into some error post the error and i will look into it then.
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  3. #3
    SitePoint Member
    Join Date
    Sep 2004
    Location
    asdasdsad
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much ill test it



  4. #4
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problem, hope this will help you
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  5. #5
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, in alltrim function i am using isEmpty function and forgot to post it. Here is the function:

    function isEmpty(s)
    {
    return ((s == null) || (s.length == 0))
    }
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •