Results 1 to 11 of 11

Thread: JavaScript - Validation Function [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Resolved JavaScript - Validation Function [RESOLVED]

    I need to validate a text box in an ASP.NET project and am trying to use JavaScript even though I have never used it before. My task is so simply, I am embarrassed to ask; how do I ensure my string is at least 6 characters?

    Here is my existing code:
    Code:
    <script language="javascript">
    	function PasswordCheck(source, arguments)
    		{
    			if string.length(arguments.value) > 5)
    				arguments.IsValid=true;
    			else
    				arguments.IsValid=false;
    		}
    </script>
    I get an "Object Required" error when it runs.
    Last edited by simonm; Jun 7th, 2005 at 08:33 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: JavaScript - Validation Function

    NameOfString.length will give you the length of the string.

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: JavaScript - Validation Function

    I've changed my code accordingly:
    Code:
    <script language="javascript">
    	function PasswordCheck(source, arguments)
    		{
    			if arguments.value.length > 5
    				arguments.IsValid=true;
    			else
    				arguments.IsValid=false;
    		}
    </script>
    ...but I still get "Object Expected" error...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: JavaScript - Validation Function

    What is "source" and "arguments"?

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: JavaScript - Validation Function

    To clarify, I the function should be being called from the following validation control:
    Code:
    <asp:customvalidator 
    	id="CustomValidator1" 
    	runat="server" 
    	ClientValidationFunction="PasswordCheck"
    	ControlToValidate="txtPassword"
    	Display="Dynamic" 
    	ErrorMessage="The password must be at least 6 characters,">
    </asp:customvalidator>
    Last edited by simonm; Jun 6th, 2005 at 04:44 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  6. #6
    Lively Member skv_noida's Avatar
    Join Date
    May 2005
    Location
    Noida, India
    Posts
    76

    Re: JavaScript - Validation Function

    try this
    <script language="javascript">
    function PasswordCheck(source, argumentsID)
    {
    var obj = document.getelementbyid(argumentsID)
    if (obj)
    {
    if obj.value.length > 5
    return true;
    else
    return false;
    }

    }
    </script>




  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: JavaScript - Validation Function

    I still don't see how source and argument are passed to that function.

  8. #8

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: JavaScript - Validation Function

    skv_noida

    Thanks, but I can't get the function you suggested to pass the syntax check...

    Mendhak
    I still don't see how source and argument are passed to that function.
    All I can say is that I can get it working in vbScript. The validation functions are supposed to take those parameters as far as I can tell. However, I need to get this working in JavaScript...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  9. #9

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: JavaScript - Validation Function

    Doesn't anybody here know how to write validation functions for the CustomerValidator control in javascript here? I would have thought it were such a simple task, something that was common place...

    Perhaps if anyone can tell me how to declare and instantiate a string object, assign it's value from arguments.value, that would probably do it...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: JavaScript - Validation Function

    Your problem is 'value' is lowercase, the first letter should be capitalized in your script above... args.Value instead of args.value.


    Here's a tip :

    Type in 'CustomValidator' in google, and the first hit has a step-by-step on how to work with CustomValidators.

    Here's another tip:

    Next time you need help with Javascript strings, type 'Javascript Strings' into Google first...you'll get a much faster response - I guarantee it!

  11. #11

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: JavaScript - Validation Function

    Thankyou nemaroller! So Javascript's case sensitive, eh?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

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



Click Here to Expand Forum to Full Width