root / trunk / web / dojo / dojox / validate / isbn.js
History | View | Annotate | Download (770 Bytes)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.validate.isbn"]){ |
||
9 | dojo._hasResource["dojox.validate.isbn"]=true; |
||
10 | dojo.provide("dojox.validate.isbn");
|
||
11 | dojox.validate.isValidIsbn=function(_1){ |
||
12 | var _2,_3=0,_4; |
||
13 | if(!dojo.isString(_1)){
|
||
14 | _1=String(_1); |
||
15 | } |
||
16 | _1=_1.replace(/[- ]/g,""); |
||
17 | _2=_1.length; |
||
18 | switch(_2){
|
||
19 | case 10: |
||
20 | _4=_2; |
||
21 | for(var i=0;i<9;i++){ |
||
22 | _3+=parseInt(_1.charAt(i))*_4; |
||
23 | _4--; |
||
24 | } |
||
25 | var t=_1.charAt(9).toUpperCase(); |
||
26 | _3+=t=="X"?10:parseInt(t); |
||
27 | return _3%11==0; |
||
28 | break;
|
||
29 | case 13: |
||
30 | _4=-1;
|
||
31 | for(var i=0;i<_2;i++){ |
||
32 | _3+=parseInt(_1.charAt(i))*(2+_4);
|
||
33 | _4*=-1;
|
||
34 | } |
||
35 | return _3%10==0; |
||
36 | break;
|
||
37 | } |
||
38 | return false; |
||
39 | }; |
||
40 | } |