Phone number format and validation library [closed] - phone-number

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
This question asking for a phone number format API in Java got me wondering why such an API doesn't seem to exist. Given the number of validation classes available under Apache Commons, I would have thought such an API would be included.
My question is, does anyone know of a phone number formatting/validation library available in any language that could be used as a model for a small Java open source project? Also, other than the large number of different phone number formats used throughout the world, does anyone know of any reason that such a project would be infeasible?

Google recently released libphonenumber for parsing, formatting, storing and validating international phone numbers.

Such an API in any language: Number::Phone (example submodule: Number::Phone::US).
Data: the ITU's National Numbering Plans index.

At http://www.geonames.org/ they have a database you can download, theres regEx rules for phone numbers included in the country info dataset.
http://download.geonames.org/export/dump/
Look for the 'countryInfo.txt' file.
I suggest you build your own validator based upon that.

Like it was said in the answers to the other question, no one's seen any for Java, and like you said, it would be nearly impossible due to the difference of phone number formats across the world.
And if you know the different formats for the regions that you're targeting, then it's usually pretty easy to implement it in regular expressions.

You can check out Parsify Format here - https://www.mashape.com/parsify/format#endpoint-Phone-Number
It will return your number in several formats e.g.
{
"e164": "+1234567890",
"national": "234567890",
"international": "+1 234567890",
"valid": false,
"type": "UNKNOWN"
}
You can get a more extensive response if it's a real number

Phone Input field :
<input class="left" id="field" name="field" />
jquery Script:
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(1-?)?(([2-9]\d{2})|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

Related

iOS, AFNetworking - "Clear" NSSTring with JSON response [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm using AFNetworking to get JSON from the server, but response contains a little bit more then just JSON, so I cannot parse it:
array(11) {
["something"]=>
string(4) "none"
(...)
}
[[],{"JSONDataNow":
(...)
}]
Is this possible to remove other data then JSON from string?
The server is not returning JSON. It's returning a JSON-like string. Either fix the server to return JSON or write your own custom parser based on the custom rules used by the server.
Attempting to write a pre-processor that turns non-JSON string into JSON is not a good idea. You will have all the difficulties of writing a custom parser with none of the benefits of being the master of your own syntax.

Whats the complexity of adding\removing objects in NSMutableArray? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I think that to add an object we need: create new array with a bigger size + make a copy of older array + add an element. So final complexity is O(N), where N - final number of elements.
Removing - O(N) also.
Am I wrong?
Thx.
I think that to add an object we need: create new array with a bigger size + make a copy of older array + add an element.
NOOOoooo....
To add an object, no new arrays are created and done all those stuffs.
If you remember cocoa has all pointers. And if you see C/C++ with pointers, just take it as a linked list. To add a new element only its address is saved in the list, and head/tail is adjusted if required.
Same case is here with MutableArrays.
Complexity should be O(1).

What encryption could this be? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a string that looks like YB[Xf`lbt+glo
What is the encryption used to encrypt this string?
I somewhat disagree with all the negative comments. While more data would of course help, it is still quite possible to make educated guesses based on the length and charset in the sample string. Some ideas off the top of my hat:
The sample has the same length as a traditional DES crypt(1) hash, albeit unexpected characters. Could be a DES crypt(1) hash with some custom output character set. Not terribly likely but possible.
The sample could be base85/ascii85 encoded, which is 80 bits of raw data. This is a rather unusual size. It could theoretically be the output of a hash function with digest size 80 bits, or longer and shortened to 80 bits, or of a block cipher with block size 80 bits (e.g. REDOC). More likely perhaps is a stream cipher.
Part of the data could be a salt or IV, assuming base85 it could quite reasonably be 16 bits of IV and a ciphertext block of 64 bits.
It could be just 80 bits of random data as e.g. a session identifier.
That's about all that can be reasonably squeezed out of the sample above I think. Not much, but it's a start. We'd need other data and information to be able to judge what is more or less likely and to confirm or rule out some of the possibilities.
(edit after the solution was posted)
For those who are interested, this is how to decode the encoded string using code from the packed JS code and running it e.g. in spidermonkey or ideone.com:
function R(t) {
var f = "";
for (var d = 0; d < t.length; d++) {
f += String.fromCharCode(t.charCodeAt(d) ^ (1 + (t.length - d) % 32));
}
return f;
}
print(R("YB[Xf`lbt+glo"));
it returns:
WOWSlider.com
just google for that string, then you find that it is an encrypted javascript
here it appears:
http://pastebin.com/tTAL1ft0
next time, please give more information where you got this string
Strictly speaking this could be created from any number of methods of encryption.
If you knew the source you might be able to do some detective work based on their technology stack but with that string alone there is no way to know for sure.

how to match two images and find out mistakes [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a template of a letter and many of it's variations (see below) which i acquire from a digital pen :
Template
Test 1
Test 2
These letters are scaled to be in the same bounding box .
I want to detect the mistakes in the letter , like the mistake in Test 1 is that that there is a extra line , and mistake in Test 2 is that there is a missing segment . Similarly there can be a mistake in which there is a curve instead of a line segment . I want to find the parts which need to be corrected . How should i go about doing it ?
One ambiguity is that whether you only want to know the difference between your template and test image or you want to detect letter A by using your template.
As mentioned by you, the difference between your template and test image is of that extra line but i think there are more differences e.g template A is not made of straight lines rather including some curves as well but the test 1 image is approximately made up of straight lines.
These two are different problems in image processing and must be entertained differently. First you have to think what you want to do?
However, one solution is that You can divide the template and test image in sub blocks and try to find the correlation between them, if that gives matching upto a predefined threshold( you should define it intelligently) than there is no difference otherwise mark that block as difference between the template and test image.
you can use xcorr2 function in MATLAB and MATLAB help is sufficient to understand the working of this function.

difference between ++i and i++ in for loop [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I understand well how postfix and prefix increments/decrements work. But my question is, in a for loop, which is more efficient or faster, and which is more commonly used and why?
Prefix?
for(i = 0; i < 3; ++i) {...}
Or postfix?
for(i = 0; i < 3; i++) {...}
For ints in this context there is no difference -- the compiler will emit the same code under most optimization levels (I'd venture to say even in the case of no optimization).
In other contexts, like with C++ class instances, there is some difference.
In this particular case, none is actually more efficient than the other. I would expect ++i to be more commonly used, because that's what would be more efficient for other kinds of iterations, like iterator objects.
In my opinion, choosing prefix or postfix in a for loop depends on the language itself. In c++ prefix is more efficient and consistent. Because in the prefix type, compiler does not need to copy of unincremented value. Besides your value must not be an integer, if your value is an object than this prefix type is more powerful.
Either works, and one is not more efficient or faster than the other in this case. It's common for people to use ++1, maybe because that is what was used in K&R and other influential books.

Resources