我想有一種方法來確定輸入是否爲域。確定輸入是否爲域
例輸入:
@stackexchange.com
@gmail.com
@google
邏輯:如何去這樣做
1. First determine if the first character is an @
2. If the input ends in a domain ext, .X or .XX or .XXX
3. Then determine if the domain (stackexchange, gmail, google) are not blacklisted. For example I might want to blacklist gmail.
建議?這會住在控制器或模型中嗎?將正則表達式做到這一點的正確方法或將減慢?由於
思路:
1. Use params[:q][0,1]
不要忘記,域有一個可選的'.'底。 – hammar 2011-05-08 18:01:01
@Hammar,最後?真?你能舉出一個在現實生活中的例子/ – AnApprentice 2011-05-08 18:02:06
'''是DNS系統的根源,但由於它始終存在,所以拼寫出來是可選的,因此在實踐中並不常見。請參閱[完全限定的域名](http://en.wikipedia.org/wiki/Fully_qualified_domain_name)。 – hammar 2011-05-08 18:05:55