|
-
Jun 6th, 2005, 03:11 AM
#1
Thread Starter
Fanatic Member
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. 
-
Jun 6th, 2005, 04:17 AM
#2
Re: JavaScript - Validation Function
NameOfString.length will give you the length of the string.
-
Jun 6th, 2005, 04:40 AM
#3
Thread Starter
Fanatic Member
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. 
-
Jun 6th, 2005, 04:40 AM
#4
Re: JavaScript - Validation Function
What is "source" and "arguments"?
-
Jun 6th, 2005, 04:41 AM
#5
Thread Starter
Fanatic Member
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. 
-
Jun 6th, 2005, 04:43 AM
#6
Lively Member
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>
-
Jun 6th, 2005, 04:45 AM
#7
Re: JavaScript - Validation Function
I still don't see how source and argument are passed to that function.
-
Jun 6th, 2005, 04:52 AM
#8
Thread Starter
Fanatic Member
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. 
-
Jun 7th, 2005, 04:05 AM
#9
Thread Starter
Fanatic Member
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. 
-
Jun 7th, 2005, 06:33 AM
#10
I wonder how many charact
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!
-
Jun 7th, 2005, 08:31 AM
#11
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|