Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.validate.isbn"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.validate.isbn"] = true;
3
dojo.provide("dojox.validate.isbn");
4
 
5
dojox.validate.isValidIsbn = function(/* String */value) {
6
	// summary: Vadlidate ISBN-10 or ISBN-13 based on the length of value
7
	// returns: Boolean
8
	var len, sum, weight;
9
	if(typeof value!='string'){
10
		value = String(value);
11
	}
12
	value = value.replace(/[- ]/g,''); //ignore dashes and whitespaces
13
	len = value.length;
14
	sum = 0;
15
	if(len == 10){
16
		weight = 10;
17
		// ISBN-10 validation algorithm
18
		for(var i = 0; i< 9; i++){
19
			sum += parseInt(value.charAt(i)) * weight;
20
			weight --;
21
		}
22
		var t = value.charAt(9).toUpperCase();
23
		sum += t == 'X' ? 10 : parseInt(t);
24
		return sum % 11 == 0;
25
	}else if(len == 13) {
26
		weight = -1;
27
		for(var i=0; i< len; i++){
28
			sum += parseInt(value.charAt(i)) * (2 + weight);
29
			weight *= -1;
30
		}
31
		return sum % 10 == 0;
32
	}else{
33
		return false;
34
	}
35
}
36
 
37
}