项目作者: Hamadakram

项目描述 :
Ratifier is a form validation library for Android.
高级语言: Java
项目地址: git://github.com/Hamadakram/Ratifier.git
创建时间: 2017-03-11T13:49:33Z
项目社区:https://github.com/Hamadakram/Ratifier

开源协议:

下载


Ratifier

Ratifier is a form validation library for Android.
alt tag

Download

Grab via Gradle:

  1. compile 'com.irozon.ratifier:ratifier:1.0.0'

Or Maven:

  1. <dependency>
  2. <groupId>com.irozon.ratifier</groupId>
  3. <artifactId>ratifier</artifactId>
  4. <version>1.0.0</version>
  5. <type>pom</type>
  6. </dependency>

How do i use Ratifier?

To use Ratifier as your form validator, use RatifierEditText and Ratifier will handle everything.
Example for Email:

  1. <com.irozon.ratifier.RatifierEditText
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:inputType="textEmailAddress"
  5. app:emptyMessage="Enter email"
  6. app:invalidMessage="Enter valid email"
  7. app:required="true" ></com.irozon.ratifier.RatifierEditText>

And to validate use

  1. Ratifier.Valid result = Ratifier.getValidity(this);
  2. if (result.isValid()) { // Form is valid
  3. Toast.makeText(this, "Email is valid", Toast.LENGTH_SHORT).show();
  4. } else { // Form is not valid
  5. Toast.makeText(this, ratify.getErrorMsg(), Toast.LENGTH_SHORT).show();
  6. }

Attributes

Following are the attributes used by RatifierEditText for validation

Attribute Descripion
required If field is required for validation or not (true/false)
emptyMessage Message for empty field
invalidMessage Message for invalid field
inputType textEmailAddress, textPassword for email and password validation. Ratifier will validate for match password also if two fields with inputType textPassword are provided. In case of invalidation, Invalid message must be provided
minCharacters Minimum characters. Invalid message must be provided for this.
regex For validation using regex like valid phone number, credit card, IP address etc. Invalid message must be provided for this.

Values can be set from activity by:

  1. ratifierEditText.setEmptyMessage("Filed is empty");
  2. ratifierEditText.setInvalidMessage("Password should be greater than 4 characters");
  3. ratifierEditText.setRegex("/^(\+\d{1,3}[- ]?)?\d{10}$/"); // Regex for valid mobile number
  4. ratifierEditText.setMinCharacters(4);

Remember to give regex from Strings.xml

Ratifier Results

Ratifier validity result will give us:

  1. Ratifier.Valid result = Ratifier.getValidity(this);
  2. boolean isValid = result.isValid(); // boolean - If the result is valid or not.
  3. String errorMessage = result.getErrorMsg(); // String - Error Message if result is not valid.
  4. RatifierEditText ratifierEditText = result.getField(); // Will return RatifierEditText which is not valid.
  • isValid() - boolean - If the result is valid or not.
  • getErrorMsg() - String - Error Message if result is not valid.
  • getField() - RatifierEditText - Will return RatifierEditText which is not valid

Some Regex examples:

Mobile Number: /^(+\d{1,3}[- ]?)?\d{10}$/

Email Address: /^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$/

URL: /^(https?:\/\/)?([\da-z.-]+).([a-z.]{2,6})([\/\w .-])\/?$/

IP Address:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/

etc

Authors

Licence

  1. Copyright 2017 Irozon, Inc.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.