الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

confirm password

بدأه tootamuhammad في 16 أبريل 2012 · 2 رد · 2,910 مشاهدة · في قسم البرمجة بــ Javascript
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

انا طالبة ومشروعي تصميم موقع للتسوق في عملية التسجيل احتاج المستخدم يدخل كلمة المرور وتاكيدها واقارن بينهم اذا غير متساويين يطلع popup message فيها not matched

وهذي محاولتي الكود يشتغل كويس الى نقطة الباسورد مايعمل compare

<html>


<head>



<script type='text/javascript'>

function formValidator(){
var firstname = document.getElementById("firstname");
var lastname=document.getElementById("lastname");
var username=document.getElementById("username");
var password = document.getElementById("password");
var cpassword = document.getElementById("cpassword");
var email = document.getElementById("email");
var gender = document.getElementById("gender");
var address= document.getElementById("address");
if(notEmpty(firstname, "Please enter your first name")){
if(isAlphabet(firstname, "Please enter only letters for your name")){
if(notEmpty(lastname, "Please enter your lastname")){
if(isAlphabet(lastname, "Please enter only letters for your name")){
if(notEmpty(username, "Please enter your user name")){
if(notEmpty(email, "Please enter your email")){
if(emailValidator(email, "Please enter a valid email address")){
if(notEmpty(password, "Please enter your password")){
if(isNumeric(password, "Please enter a valid password")){
if(lengthRestriction(password, 6, 8)){
if(notEmpty(cpassword, "Please enter your confirm password")){
if(notEqual(password,cpassword,"your password and confimation password not matched")){

if(notEmpty(address, "Please enter your address")){


return true;

}
}
}
}
}
}
}
}
}
}
}
}
}

return false;
}

function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus();
return false;
}
return true;
}
function notEqual(pelem,celem, helperMsg){
var pinput=pelem.value;
var cinput=celem.value;
if(pinupt !=cinput ){
alert(helperMsg);
elem.focus();
return false;
}
return true;
}
/*
^ it matches the starting position of any line.
& it matches the ending position of any line.
[0-9] matches any number between 0-9.

*/
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
/*
^ it matches the starting position of any line.
& it matches the ending position of any line.
[a-zA-Z] matches alphapitc chracter uppercase and lowercase
*/

function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}



function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
}else{
alert("Please enter between " +min+ " and " +max+ " numbers");
elem.focus();
return false;
}
}


/*
Email format: The regular expression for email is /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
/^[a-zA-Z0-9._-]+: Means that the email address must begin with alpha-numeric characters(both lowercase and uppercase characters are allowed).
It may have periods,underscores and hyphens.
@: There must be a ‘@’ symbol after initial characters.
[a-zA-Z0-9.-]+: After the ‘@’ sign there must be some alpha-numeric characters. It can also contain period (‘.’) and and hyphens(‘-’).
\.: After the second group of characters there must be a period (‘.’). This is to separate domain and subdomain names.
[a-zA-Z]{2,4}$/: Finally, the email address must end with two to four alphabets. Having a-z and A-Z means that both lowercase and uppercase letters are allowed.
{2,4} indicates the minimum and maximum number of characters. This will allow domain names with 2, 3 and 4 characters e.g.; us, tx, org, com, net, wxyz).

*/
function emailValidator(elem, helperMsg){
var emailExp =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/ ;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();

return false;
}
}
function checkAnswers (elem,helperMsg){

if(document.getElementById("gender1").checked || document.getElementById("gender").checked){
return true;
}else{alert(helperMsg);


return false;
}
}

</script>


</head>
<title>
test majors
</title>




<form name="myform" class="divform" method="post" action="" onsubmit="return formValidator()">

<p> first Name:<input name="fname" id="firstname" type="text" size="25" maxlength="40"/></p>
<p> last Name:<input name="lname" id="lastname" type="text" size="25" maxlength="40"/></p>
<p>userName:<input name="username" id="username" type="text" size="25" maxlength="40"/></p>
<p>E-mail<input name="mail" type="text" size="25" maxlength="40" id="email"/></p>
<p> password:<input name="password" type="password" size="25" maxlength="10" id="password"/>
<p> confirm password:<input name="cpassword" type="password" size="25" maxlength="10" id="cpassword"/>

<p>address:<input type = "text" name = "address" id="address" /></p>



<p> <input type="submit" value="submit"/><input type="reset" value="clear"/>
</p>

</form>




</body>
</html>

test.html

تم تعديل هذه المشاركة بواسطة tootamuhammad في 16 أبريل 2012 في 23:58

#2

الرجاء مساعدتي في functions المقارنة بين password و confirm password اللي هي notEqual

لان موعد تسليم مشروعي اقترب وحاولت في الكود كثيير ولكن للاسف لم اعرف المشكلة

القصد انو كل functions شغالة ماعدا notEqual لا تعمل ولم اعرف السبب

الرجاء لو شرح بسيط عن سبب عدم عملها

تم تعديل هذه المشاركة بواسطة tootamuhammad في 29 أبريل 2012 في 20:59

#3

اختي الخطأ بسيط جدا ً في دالة notEqual على هذه الجملة

elem.focus();

الخطأ في elem المفروض تكون celem بهذا الشكل

celem.focus();

الكائن elem غير موجود استخدمتيه في دوال اخرى لكن في هذه الدالة لم تستخدميه لذلك صار معك هذا الخطأ

فقط عدليه وراح يشتغل معاكي بشكل سليم ^_^

M.B.O

Mohamed Bin Othman

إبن المكلا

يابني البشر ماذا فعلتم بالبشر !!

إسـألـنـي

مواضيع مشابهة