# Regex test if valid asset name

**URL:** <https://forums.counterparty.io/t/regex-test-if-valid-asset-name/1640>\
**Category:** 3rd Party\
**Created:** [November 14, 2015, 1:21pm UTC](https://forums.counterparty.io/t/regex-test-if-valid-asset-name/1640 "2015-11-14T13:21:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPJA](https://yyz2.discourse-cdn.com/flex004/user_avatar/forums.counterparty.io/jpja/32/1324_2.png) [@JPJA](https://forums.counterparty.io/u/JPJA)\
**Post date:** [November 14, 2015, 1:21pm UTC](https://forums.counterparty.io/t/regex-test-if-valid-asset-name/1640/1 "2015-11-14T13:21:00Z")

</div>

The regular expression **/\[1\][A-Z]{3,11}$/** tests whether a string is a valid asset name.

To allow for lowercase characters, use **/\[2\][a-zA-Z]{3,11}$/**

**/\b[B-Z][A-Z]{3,11}\b/** finds the first valid uppercase asset name within the string.

Add **g** to find all asset names; **/\b[B-Z][A-Z]{3,11}\b/g**

…  
You can test a regex on [[regex101.com](http://regex101.com)][1].

 ![](https://canada1.discourse-cdn.com/flex004/uploads/counterpartytalk/original/1X/66b170589e58f6699f9a21df2423b2ecbc6abd95.PNG)

…  
For example, to find all assets within a string with PHP, you may use this code:

```
$text = 'My favorite XCP assets are FLDC, BITCRYSTALS and YACHTMONEY!';
preg_match_all('/\b[B-Z][A-Z]{3,11}\b/', $text, $matches);
for ($i = 0; $i < count($matches[0]); ++$i) {
    print $matches[0][$i].' ';
}

```

Note: A valid asset name needs to meet four conditons

- Only characters A-Z
- First character not A
- Minimum length is 4
- Maximum length is 12

Earlier it was possible to register longer names. There are a few 13 and 14 character names, but none of these are in active use.  
[1]: [https://regex101.com/](https://regex101.com/)

* * *

1. B-Z 

2. b-zB-Z

---

<div class="post-metadata">

**Author:** ![JPJA](https://yyz2.discourse-cdn.com/flex004/user_avatar/forums.counterparty.io/jpja/32/1324_2.png) [@JPJA](https://forums.counterparty.io/u/JPJA)\
**Post date:** [November 17, 2015, 11:10am UTC](https://forums.counterparty.io/t/regex-test-if-valid-asset-name/1640/2 "2015-11-17T11:10:40Z")

</div>

Another PHP example.

To test if a string is a valid asset name, use this code:

```
$asset = 'MYASSET';
if (preg_match('/^[B-Z][A-Z]{3,11}$/', $asset)) {
	echo "$asset is a valid asset name"; 
} else {
	echo "$asset is NOT a valid asset name"; 
}
```

---

<div class="post-metadata">

**Author:** ![JPJA](https://yyz2.discourse-cdn.com/flex004/user_avatar/forums.counterparty.io/jpja/32/1324_2.png) [@JPJA](https://forums.counterparty.io/u/JPJA)\
**Post date:** [January 26, 2016, 9:54am UTC](https://forums.counterparty.io/t/regex-test-if-valid-asset-name/1640/3 "2016-01-26T09:54:32Z")

</div>

Javascript tests for both alphabetic and numeric asset names:

> [@Regex test for numeric asset names](https://forums.counterparty.io/t/regex-test-for-numeric-asset-names/1737/3):
>
> I think I got it here. Tested with all edge cases and seems to work, at least if the min and max assumptions are correct. I did not use BigInt because one does not always want to import a library. function isValidAsset(asset) { if (isValidAlphabeticAsset(asset) || isValidNumericAsset(asset)) return true; return false; } function isValidAlphabeticAsset(asset) { //4-12 chars, cannot start with A //A few old ones have 13 or 14 chars if (asset.match(/^[B-Z][A-Z]{3,11}$/) == null) return fals…
