...

View Full Version : Resolved Help with checking user input



RachN92
04-20-2011, 08:47 PM
_________

gusblake
04-20-2011, 09:02 PM
String.indexOf() can be used to detect the occurence of one string within another. The "length" property holds the number of characters in a string.



alert("string".length); //6
alert("string".indexOf("t")); //1
alert("string".indexOf("g")); //5
alert("string".indexOf("a")); //-1

RachN92
04-20-2011, 09:49 PM
String.indexOf() can be used to detect the occurence of one string within another. The "length" property holds the number of characters in a string.


Thanks, sort of makes sense. I have to use a WHILE loop but am unsure of how to implement this :confused:

It is an assignment for uni, so dont give me a full answer cos that would be cheating :)

but could you give me an example say if the user has to enter their email address but it has to contain '@' and be a maximum of 30 characters...

Philip M
04-20-2011, 10:31 PM
Thanks, sort of makes sense. I have to use a WHILE loop but am unsure of how to implement this :confused:

It is an assignment for uni, so dont give me a full answer cos that would be cheating :)

but could you give me an example say if the user has to enter their email address but it has to contain '@' and be a maximum of 30 characters...

Show the code you have written, then I am sure that someone will correct/improve it.

But simply to check that an email address contains an @ sign is almost worthless as a validation. And why maximum of 30 characters? The maximum permitted is 254 characters, although I doubt if many actual ones are that long. I would have thought that max 50 characters would suffice.

RachN92
04-20-2011, 10:37 PM
Show the code you have written, then I am sure that someone will correct/improve it.

But simply to check that an email address contains an @ sign is almost worthless as a validation. And why maximum of 30 characters? The maximum permitted is 254 characters, although I doubt if many actual ones are that long. I would have thought that max 50 characters would suffice.

that may be so, but it was simply an example. I need to code it so a user enters a password that is not less than 7 characters long, contains a * symbol and starts with 'Z'

i cannot show the code because i cant write it as that ^^^^ is what i am stuck on.
I was hoping to receive some useful answers that might help me code it...

Philip M
04-21-2011, 11:55 AM
You said "It is an assignment for uni, so dont give me a full answer cos that would be cheating". Yet now you want us to write the code for you. It would have been preferable if you had made at least an attempt yourself.
I do not see how your email question relates to your password question.
"I need to code it so a user enters a password that is not less than 7 characters long, contains a * symbol and starts with 'Z'".




PASSWORD <input type = "text" id = "pwd" onblur = "chkit()">

<script type = "text/javascript">
function chkit() {
var p = document.getElementById("pwd").value;
if ((p.length <7) || (p.charAt(0)!= "Z") || (p.indexOf("*") == -1)) {
alert ("Invalid password");
}
else {
alert ("Password is OK");
}

}

</script>

You should be aware that if the hacker knows that your password must start with a Z and inckude a * then the password is less secure than the same number of unrestricted characters.

Why have you deleted the first post in the thread?

RachN92
04-21-2011, 03:29 PM
It didnt relate to it at all it was simply a change in scenario so you didnt give me the full answer for the REAL scenario i have been given. Also, i couldnt care less i it makes it less secure, its not going to be used its simply an exercise. Therefore i see no issue here.

However, thanks for the code. i will try it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum