From this question we know that we cannot verify ipfs hash exist beforehand.
IPFS is a decentralized system, there is no central domain where you can do a lookup to find your hash. When looking up files, you're asking the network to find nodes storing the content behind a unique hash. You cannot know whether it exists beforehand.
When we add a folder or file into IPFS it will generate some ipfs hash for example:
QmXjkFQjnD8i8ntmwehoAHBfJEApETx8ebScyVzAHqgjpD. It seems like all hashes start with "Qm" and has 46 characters (if I didn't count it wrong). Is these cases are always true?
$ ipfs add -r folder
added QmXjkFQjnD8i8ntmwehoAHBfJEApETx8ebScyVzAHqgjpD folder/avatar/avatar.c
[Q] How could I verify a input string if the string always have some properties to be an ipfs hash? The goal of this to force user to enter at least string that matches the size of the ipfs hash and other properties if exist.
- String should start with "Qm"
- String should be 46 characters.