Skip to content

A minimal library of useful Persian / Farsi regular expressions for browser and NodeJS environment

License

Notifications You must be signed in to change notification settings

alihaddadkar/persianRex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

persianRex

A minimal library of useful Persian / Farsi regular expressions for browser and NodeJS environment

travis-ci

##Places that you can use persianRex persianRex features

##Getting started You can download the latest release form the release page or use your preferred package manager.

via npm

npm install persian-rex --save

via bower

bower install persian-rex --save

Once downloaded you can include the dist file like this:

 <scirpt src="bower_components/persian-rex/dist/persian-rex.js"></script>

Or if you are using node:

 var persianRex = require('persian-rex');

###Detecting Persian Numbers The number RegExp will match any string that only contains Persian numbers.

 if (persianRex.number.test('۱۲۳'))
  makeInputsRTL();

###Detecting Persian Letters The letter RegExp will match any string that only contains Persian letters.

 if (persianRex.letter.test('ابپ'))
  makeInputsRTL();

###Detecting Persian Text The text RegExp will match any string that only contains Persian letters or Persian numbers.

 if (persianRex.text.test('ابپ۱۲۳'))
  makeInputsRTL();

###Using has prefix You can prefix any of the above methods with has.

 if (persianRex.hasNumber.test('ابپ۱۲۳۴۵۶123abc'))
  makeInputsRTL();

The if condition is true, because the string has a persian number in it. You can use hasLetter and hasText as well.

###Lower level usage You can also get the ASCI code ranges for Persian numbers and Persian letters to make your custom RegExps.

  var customLettersRegular = new RegExp('^' + persianRex.lettersASCIRange);
  var customNumberRegular = new RegExp('^' + persianRex.numbersASCIRange);

#Sponsors Many of regular expressions in this project is extracted from larger projects such as Themeyab.com, If you think I'm are missing an important regular expression, feel free to open an issue on this repository and I will include it in the next version.

Themeyab Logo

About

A minimal library of useful Persian / Farsi regular expressions for browser and NodeJS environment

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%