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

ما هو المرادف في ASP.NET؟

مغلق
بدأه jrahma في 4 مايو 2006 · 5 رد · 672 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لدي هذا الكود في JavaScript وأريد أن أعرف المرادف لها الأوامر في ASP.NET

BirthMonth = cLng( mid(Cpr, 3, 2))

If Digit9 <> CPR Mod 10 Then
#3

ماذا عن Mod 11؟

#4

بالنسبه لل mod

إذا كنت تستخدم C# المرادف %

أما في الVB فهي نفس الشيء Mod

#5

this is the code which i got from the government to validate the card number and i converted to C# but if i validate using the java it's ok.. but when i try with C# it's invalid...

Please help

FIRST HERE ARE VALID CARDS

731004167
601002989
720404312
570110556
820801950

THIS IS JAVA CODE:

<script language="vbscript" >
Function ValidCPR(CPR )
' function will return one of the following values
' 0 = no error
' 1 = Invalid CPR length
' 2 = Invalid month in CPR
' 3= Invalid CPR number (digit9)

Dim Total , i
Dim Remainder , Digit9
Dim BirthMonth

' default value
ValidCpr = 0

' 1: check cpr length
If Len(CPR) <> 9 Then
ValidCPR = 1
else

' 2: check month value, digit 3 and 4, it should be from 00 to 12
BirthMonth = cLng( mid(Cpr, 3, 2))
If BirthMonth > 12 then
ValidCPR = 2
Else

' 3: check digit 9
Total = 0
For i = 1 To 8
Total = Total + cLng(Mid(CPR, i, 1)) * (10 - i)
Next
Remainder = Total Mod 11
If Remainder < 2 Then
Digit9 = 0
Else
Digit9 = 11 - Remainder
End If
If Digit9 <> CPR Mod 10 Then
ValidCPR = 3
End If
End If
End If
End Function

sub cmdCheck_onclick
err= ValidCpr( document.frm1.txtCpr.value)
if err = 0  then
  msgBox "CPR Ok"
else
  msgBox " CPR error#" & err
end if
end sub

</script>

AND THIS IS C# CODE

enum CprState
{
   Valid = 0,
   InvalidLength = 1,
   InvalidMonth = 2,
   InvalidNumber = 3
}

CprState ValidateCpr(string cpr)
{
  // 1: check cpr length
if (string.IsNullOrEmpty(cpr) || cpr.Length != 9)
   return CprState.InvalidLength;

// 2: check month value, digit 3 and 4, it should be from 00 to 12
if (long.Parse(cpr.Substring(2, 2)) > 12)
   return CprState.InvalidMonth;

long cprNumber = long.Parse(cpr);
long cprDigit = 0;
// 3: check digit 9
long total = 0;
for (int i = 9; i > 0; i--)
{
   cprDigit = cprNumber % 10;
   cprNumber = cprNumber / 10;
   total += cprDigit * i;
}

long remainder = total % 11;
long lastDigit = remainder < 2 ? 0 : 11-remainder;
if (lastDigit != cprDigit)
   return CprState.InvalidNumber; 


return CprState.Valid;

}
#6

I am sorry if i am pushing this

but

it's extremlly urgent

thanks

هذا الموضوع مغلق.

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